Created
January 13, 2021 11:20
-
-
Save kucherenko/2a687f15d6d35f2455d2720a660d754b to your computer and use it in GitHub Desktop.
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, ...args) => { | |
return fn.length <= args.length ? fn(...args) : curry.bind(null, fn, ...args); | |
} | |
// Example | |
const sum = (a, b, c) => a + b + c; | |
curry(sum)(3)(4)(5); // 12 | |
curry(sum)(3, 4, 5); // 12 | |
curry(sum, 3)(4, 5); // 12 | |
curry(sum, 3)(4)(5); // 12 | |
curry(sum, 3, 4)(5); // 12 | |
curry(sum, 3, 4, 5); // 12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment