Created
October 13, 2016 15:20
-
-
Save suciuvlad/fb63ddeb3e153b47d4630fe3696d5cc5 to your computer and use it in GitHub Desktop.
Curried Add
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 add(a,b,c){ return a+b+c; } | |
| function curry(fn) { | |
| return function curried() { | |
| var args = [].slice.call(arguments); | |
| return args.length >= fn.length ? | |
| fn.apply(null, args) : | |
| function () { | |
| var rest = [].slice.call(arguments); | |
| console.log(args); | |
| return curried.apply(null, args.concat(rest)); | |
| }; | |
| }; | |
| }; | |
| var curriedAdd = curry(add); | |
| curriedAdd(1)(2)(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment