Created
May 22, 2020 11:14
-
-
Save ashish-r/4853e3ff85b12ad355e91dff3ae5c2b5 to your computer and use it in GitHub Desktop.
A simple approach to curry any function.
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(func){ | |
return function temp(...args) { | |
if (args.length < func.length) { | |
return temp.bind(null, ...args) | |
} | |
return func(...args) | |
} | |
} | |
var getSum = function (a, b, c, d, e) { return a + b + c + d + e; } | |
console.log(curry(getSum)(15)(20)(25)(30)(35)) // 125 | |
console.log(curry(getSum)(15, 20)(25, 30)(35)) // 125 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment