Created
October 12, 2009 17:57
-
-
Save jfarmer/208582 to your computer and use it in GitHub Desktop.
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
var inject = function(iterable, initial, func) { | |
var cur = initial | |
for(var i = 0;i < iterable.length;i++) { | |
cur = func(cur, iterable[i]) | |
} | |
return cur | |
} | |
var map = function(arr, func) { | |
return inject(arr, [], function(memo, val) { | |
memo.push(func(val)) | |
return memo | |
}) | |
} | |
map([1,2,3], function(x) { return x + 1 }) // #=> [2,3,4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment