Skip to content

Instantly share code, notes, and snippets.

@psenger
Created October 20, 2020 22:18
Show Gist options
  • Select an option

  • Save psenger/b14451bc84100e32d3784ded7d0fccad to your computer and use it in GitHub Desktop.

Select an option

Save psenger/b14451bc84100e32d3784ded7d0fccad to your computer and use it in GitHub Desktop.
[Curry] #JavaScript
const curry = function curry(func) {
return function curried(...args) {
if (args.length >= func.length) {
return func.apply(this, args);
} else {
return function(...args2) {
return curried.apply(this, args.concat(args2));
}
}
};
}
function sum(a, b, c) {
return a + b + c;
}
let curriedSum = curry(sum);
console.log(curriedSum(1)(2)(3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment