It doesn't look like normal currying to me. You're not using the returned curried function (if there is one).
Anyway. Here is mine. Don't judge me.
functioncurry(fn,arity){if(arguments.length===1){// you won't tell me? Fine, I'll guess.arity=fn.length;if(arity===0){// you are a sneaky one.// you trying to curry a variadic function?// hope you know what you're doing.returncurry.bind(null,fn,{last:0});}}// Gather the relevant arguments.varrest=Array.prototype.slice.call(arguments,2);vararity_satisfied=arity<=rest.length;// for that edge case. If it is the same you didn't add new arguments.varcalled_withoutarguments=arity.last===rest.length;if(arity_satisfied||called_withoutarguments){returnfn.apply(fn,rest);}if(typeofarity.last=='number'){// state. Remember the arguments count.arity.last=rest.length;}// you can blame `bind` for not taken an array.varargs=[null,fn,arity].concat(rest);// call `bind` with `args` and give me a function.returncurry.bind.apply(curry,args);}
Oh and the test. The test was fun. Did you know that the assert module on node had a strict mode? I didn't.
// this is done with mocha// mocha --ui qunit -r esm test/**/*.test.jsimport{strictast}from'assert';import{curry}from'../../src/utils';suite('# curry');test('variadic function without arguments list',function(){functionadd(){return[].slice.call(arguments).reduce(function(a,b){returna+b},0);}letcurried=curry(add);t.equal(typeofcurried,'function','curried is a function');letcurried_1=curried(1)(1,2,3)(2)(2,5);t.equal(typeofcurried_1,'function','still currying');t.equal(curried_1(),16,'stops when no argument is supplied');});
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.
I don't know what's going on with those weird
curryAdder
calls.It doesn't look like normal currying to me. You're not using the returned curried function (if there is one).
Anyway. Here is mine. Don't judge me.
Oh and the test. The test was fun. Did you know that the
assert
module on node had astrict
mode? I didn't.