Created
October 20, 2020 22:18
-
-
Save psenger/b14451bc84100e32d3784ded7d0fccad to your computer and use it in GitHub Desktop.
[Curry] #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
| const curry = function curry(func) { | |
| return function curried(...args) { | |
| if (args.length >= func.length) { | |
| return func.apply(this, args); | |
| } else { | |
| return function(...args2) { | |
| return curried.apply(this, args.concat(args2)); | |
| } | |
| } | |
| }; | |
| } | |
| function sum(a, b, c) { | |
| return a + b + c; | |
| } | |
| let curriedSum = curry(sum); | |
| console.log(curriedSum(1)(2)(3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment