Skip to content

Instantly share code, notes, and snippets.

@ashish-r
Created May 22, 2020 11:14
Show Gist options
  • Save ashish-r/4853e3ff85b12ad355e91dff3ae5c2b5 to your computer and use it in GitHub Desktop.
Save ashish-r/4853e3ff85b12ad355e91dff3ae5c2b5 to your computer and use it in GitHub Desktop.
A simple approach to curry any function.
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