RosettaCodeData/Task/First-class-functions/ActionScript/first-class-functions.as

22 lines
510 B
ActionScript
Raw Permalink Normal View History

2013-10-27 22:24:23 +00:00
var cube:Function = function(x) {
return Math.pow(x, 3);
};
var cuberoot:Function = function(x) {
return Math.pow(x, 1/3);
};
2013-04-10 21:29:02 -07:00
function compose(f:Function, g:Function):Function {
return function(x:Number) {return f(g(x));};
}
2013-10-27 22:24:23 +00:00
var functions:Array = [Math.cos, Math.tan, cube];
var inverse:Array = [Math.acos, Math.atan, cuberoot];
2013-04-10 21:29:02 -07:00
function test() {
for (var i:uint = 0; i < functions.length; i++) {
2013-10-27 22:24:23 +00:00
// Applying the composition to 0.5
trace(compose(functions[i], inverse[i])(0.5));
2013-04-10 21:29:02 -07:00
}
}
2013-10-27 22:24:23 +00:00
test();