Skip to content

Instantly share code, notes, and snippets.

@HelderFigueiredo
Last active February 5, 2018 06:23
Show Gist options
  • Select an option

  • Save HelderFigueiredo/651133f1bbe5e210a200aed088ef23f7 to your computer and use it in GitHub Desktop.

Select an option

Save HelderFigueiredo/651133f1bbe5e210a200aed088ef23f7 to your computer and use it in GitHub Desktop.
Currify a function.
function curry(...args) {
let storedArgs = args.slice(1);
const fn = args[0];
const fnArgsLen = fn.length;
const curriedFn = (...newArgs) => {
let currentArgs = [...storedArgs, ...newArgs];
if (currentArgs.length >= fnArgsLen) {
return fn(...(currentArgs.slice(0, fnArgsLen)));
}
return curry(fn, ...currentArgs);
};
return curriedFn;
}
module.exports = curry;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment