Created
May 21, 2011 19:37
-
-
Save stevegraham/984829 to your computer and use it in GitHub Desktop.
JavaScript Array#map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.map = function(func) { | |
var output = [] | |
for(i=0; i < this.length; i++) { | |
output[i] = func(this[i]) | |
} | |
return output | |
} | |
// Example usage: | |
// [1,2,3].map(function(i) { return i * i }) | |
// returns [1, 4, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment