Last active
December 19, 2015 19:19
-
-
Save efleming969/6005582 to your computer and use it in GitHub Desktop.
Example Curry Function 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 curry = function(fn) { | |
| var result = function() { | |
| var newArgs = Array.prototype.slice.call(arguments, 0); | |
| if (newArgs.length >= fn.length) { | |
| var finalResult = fn.apply(null, newArgs); | |
| return finalResult; | |
| } else { | |
| return Function.prototype.bind.apply(result, [null].concat(newArgs)); | |
| } | |
| }; | |
| return result; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment