Skip to content

Instantly share code, notes, and snippets.

@Sidd27
Last active September 10, 2021 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Sidd27/c483bca349214f94ecf98283da6c4ce2 to your computer and use it in GitHub Desktop.
Save Sidd27/c483bca349214f94ecf98283da6c4ce2 to your computer and use it in GitHub Desktop.
Curry Function in ES5 (Javascript) It returns the curried function
function curry(fn) {
var arity = fn.length;
return (function resolver() {
var memory = Array.prototype.slice.call(arguments);
return function () {
var local = memory.slice(),
next;
Array.prototype.push.apply(local, arguments);
next = local.length >= arity ? fn : resolver;
return next.apply(null, local);
};
}());
}
const es6Curry = (f, arr = []) => (...args) => (
a => a.length === f.length ? f(...a) : es6Curry(f, a)
)([...arr, ...args]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment