Apply a callback to an array: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1: | Line 1: | ||
{{task}}In this task, the goal is to take a combined set of elements and apply a function to each element. |
{{task}}In this task, the goal is to take a combined set of elements and apply a function to each element. |
||
=={{header|ActionScript}}== |
|||
<actionscript> |
|||
package |
|||
{ |
|||
public class ArrayCallback |
|||
{ |
|||
public function main():void |
|||
{ |
|||
var nums:Array = new Array(1, 2, 3); |
|||
nums.map(function(n:Number, index:int, arr:Array):void { trace(n * n * n); }); |
|||
// You can also pass a function reference |
|||
nums.map(cube); |
|||
} |
|||
private function cube(n:Number, index:int, arr:Array):void |
|||
{ |
|||
trace(n * n * n); |
|||
} |
|||
} |
|||
} |
|||
</actionscript> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{works with|GNAT|GPL 2005}} |
{{works with|GNAT|GPL 2005}} |