Skip to content

Instantly share code, notes, and snippets.

@ecasilla
Created November 19, 2014 17:15
Show Gist options
  • Select an option

  • Save ecasilla/e82bfc12f1976e0344aa to your computer and use it in GitHub Desktop.

Select an option

Save ecasilla/e82bfc12f1976e0344aa to your computer and use it in GitHub Desktop.
Currying In Js
function curry(fn) {
//create sunt double function to check artiy of the calling function i.e fn
return function() {
//check the length of args and if its greater copy them and return a new function
if (fn.length > arguments.length) {
//copy logic
var slice = Array.prototype.slice;
var args = slice.apply(arguments)
//new function with args copied
return function() {
return fn.apply(
null, args.concat(slice.apply(arguments)));
};
}
//else just pass the arguments back to the original
return fn.apply(null, arguments);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment