Created
July 7, 2023 12:18
-
-
Save lqt0223/df294231d52f085efa8d64ca147c6967 to your computer and use it in GitHub Desktop.
39 currying
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
function curry(fn) { | |
return function curried(...args) { | |
if (args.length >= fn.length) { | |
return fn.call(this, ...args) | |
} else { | |
return curried.bind(this, ...args) | |
} | |
} | |
} | |
const _add3 = (a, b, c) => a + b + c | |
const add3 = curry(_add3) | |
// console.log(add3(1)(2)(3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment