Created
April 28, 2011 12:24
-
-
Save softprops/946248 to your computer and use it in GitHub Desktop.
functional fold in javascript
This file contains hidden or 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 foldl = function(f, init, l) { | |
switch(l.length) { | |
case 0: return init; | |
default: return arguments.callee( | |
f, f(init, l[0]), l.slice(1) | |
); | |
} | |
}; |
This file contains hidden or 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 foldr = function(f, init, l) { | |
return foldl(f, init, l.reverse()); | |
}; |
ghost
commented
Sep 18, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment