Last active
June 4, 2020 10:39
-
-
Save leonidkuznetsov18/41faa95c6b6406ed165fe94fd193620b to your computer and use it in GitHub Desktop.
curry (multiple arguments)
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 curry(func) { | |
| return function curried(...args) { // REST arguments to array | |
| if (args.length >= func.length) { | |
| return func.apply(this, args); | |
| } else { | |
| return function(...args2) { | |
| return curried.apply(this, args.concat(args2)); | |
| } | |
| } | |
| }; | |
| } | |
| function log(d, m, y) { | |
| console.log(`Day: ${d}, Month:${m}, Year:${y} `); | |
| } | |
| const logCurr = curry(log); | |
| const logNow = logCurr('Monday'); | |
| logNow('Sep')(1993) | |
| logNow('Nov', 1994) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment