Nice function - one thing I noticed is that calling the curry function's callback with all the arguments provided at once or one at a time, you get back the same result.
I would also recommend throwing an error when there is a mismatch between the number of supplied args and the number of args the function actually needs.
For example, the code below will throw a different error when the curried function is partially applied versus when then curried function is called with all arguments at once.
constisEveryArgumentProvided=x=>y=>x>=y;functioncurry(f){functioncurried(...initialArgs){if(initialArgs.length>f.length){thrownewError(`Function \`${f.name}\` supplied ${initialArgs.length} args when expecting ${f.length} args`);}returnisEveryArgumentProvided(initialArgs.length)(f.length)?f.apply(this,initialArgs)// received all args for f:(...remainingArgs)=>curried.apply(this,[...initialArgs,...remainingArgs])// more args needed for f;}returncurried;}constadder=(x,y)=>x+y;constcurriedAdder=curry(adder);curriedAdder(1)(2)(3);//=> Error: curriedAdder(...)(...) is not a functioncurriedAdder(1,2,3);//=> Error: Function `adder` supplied 3 args when expecting 2 args
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice function - one thing I noticed is that calling the curry function's callback with all the arguments provided at once or one at a time, you get back the same result.
For example:
I would also recommend throwing an error when there is a mismatch between the number of supplied args and the number of args the function actually needs.
For example, the code below will throw a different error when the curried function is partially applied versus when then curried function is called with all arguments at once.