Skip to content

Instantly share code, notes, and snippets.

@suciuvlad
Created October 13, 2016 15:20
Show Gist options
  • Select an option

  • Save suciuvlad/fb63ddeb3e153b47d4630fe3696d5cc5 to your computer and use it in GitHub Desktop.

Select an option

Save suciuvlad/fb63ddeb3e153b47d4630fe3696d5cc5 to your computer and use it in GitHub Desktop.
Curried Add
function add(a,b,c){ return a+b+c; }
function curry(fn) {
return function curried() {
var args = [].slice.call(arguments);
return args.length >= fn.length ?
fn.apply(null, args) :
function () {
var rest = [].slice.call(arguments);
console.log(args);
return curried.apply(null, args.concat(rest));
};
};
};
var curriedAdd = curry(add);
curriedAdd(1)(2)(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment