Last active
October 30, 2018 16:07
-
-
Save guz-anton/dc6f6dd5993290ba0dde094c10b175d5 to your computer and use it in GitHub Desktop.
Redusing arguments
This file contains 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 = (fn, ...initialArgs) => { | |
let value; | |
const fnx = (...curryArgs) => { | |
value = fn.apply(null, initialArgs.concat(curryArgs)); | |
return fnx; | |
} | |
Object.defineProperty(fnx, 'valueOf', {value: () => value}); | |
return fnx; | |
} |
This file contains 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 = (fn, ...initialArgs) => { | |
let value; | |
const fnx = (...curryArgs) => { | |
if(initialArgs.length || curryArgs.length) { | |
value = initialArgs.concat(curryArgs).reduce(fn); | |
} | |
return fnx; | |
} | |
Object.defineProperty(fnx, 'valueOf', {value: () => value}); | |
return fnx(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment