Skip to content

Instantly share code, notes, and snippets.

@sematgt
Created January 9, 2021 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sematgt/b3b70a00216277d95f4933de1988727b to your computer and use it in GitHub Desktop.
Save sematgt/b3b70a00216277d95f4933de1988727b to your computer and use it in GitHub Desktop.
curry function
function sum(a, b, c) {
return a + b + c;
}
function curry(func) {
return function curried(...args) {
if (args.length >= func.length) {
return func.apply(this, args);
} else {
return function pass(...args2) {
return curried.apply(this, args.concat(args2))
}
}
}
}
let curriedSum = curry(sum);
console.log(curriedSum(1)(2)(3))
console.log(curriedSum(1, 2)(3))
console.log(curriedSum(1)(2, 3))
console.log(curriedSum(1, 2, 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment