Created
December 15, 2013 15:57
-
-
Save cuipengfei/7974641 to your computer and use it in GitHub Desktop.
functional js curry
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
| function curryN(fn, n) { | |
| function wrapper(args) { | |
| return function (oneArg) { | |
| var argsConcat = args.concat(oneArg) | |
| if (argsConcat.length == ( n || fn.length)) { | |
| return fn.apply(this, argsConcat) | |
| } | |
| return wrapper(argsConcat) | |
| } | |
| } | |
| return wrapper([]) | |
| } | |
| module.exports = curryN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment