4 ms·
The article's implementation grows the stack unnecessarily through recursively nested closures. A commenter pointed out a flaw in my code. This new implementati
by goldenkey 5y ago
The article's implementation grows the stack unnecessarily through recursively nested closures. A commenter pointed out a flaw in my code. This new implementation is even faster and more concise by doing away with the closures (other than the single inner closure):
const curry = fn => {
const curried = (...a) => a.length >= fn.length ? fn(...a) : curried.bind(undefined, ...a)
return curried
}
It uses bind which is an extremely powerful operator (a function that maps functions to functions)