args
) is sufficient, call the passed function fn
.Function.prototype.bind()
to return a curried function fn
that expects the rest of the arguments.Math.min()
), you can optionally pass the number of arguments to the second parameter arity
.const curry = (fn, arity = fn.length, ...args) =>
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
curry(Math.pow)(2)(10); // 1024
curry(Math.min, 3)(10)(50)(2); // 2
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️