Before I get into the code, lets take a look at how the map function works. The method signature for map looks like this: public Array function map(Array arr, function fn). The map function takes and array and a function as parameters, and returns an array. Each element in the array argument is passed into the function and the result is added to the result.
Without further adu, lets take a look a the code:
Running this code would produce this result:
Now this pattern can be applied anywhere you find yourself looping through an array and applying the same logic to each member of the array.