Array map

Actionscript:
  1. var a:Array = [1,2,3,4,5,6];
  2. var double:Array = a.map(function():int{return arguments[0] * 2});
  3. trace(double);
  4. /*outputs:
  5. 2,4,6,8,10,12
  6. */

A condensed example of Array.map()

Here is the same thing written in haskell:

a = [1,2,3,4,5,6]
double = map (*2) a

main = print double
This entry was posted in arrays, functions and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*