Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function fixCurry(fn, totalArgs){
totalArgs = totalArgs ||fn.length
return function recursor(){
return arguments.length<fn.length?recursor.bind(this, ...arguments): fn.call(this, ...arguments);
}
}
var add = fixCurry((a,b,c)=>a+b+c);
console.log('Add')
console.log(add(1,2, 3))
console.log(add(1)(2,3))
console.log(add(1)(3)(2))
console.log(add(1,2)(3))
var mul = fixCurry((a,b,c)=>a*b*c);
console.log('Multiple')
console.log(mul(1,2,3))
console.log(mul(1)(2,3))
console.log(mul(1)(3)(2))
console.log(mul(1,2)(3))
@pantomath91
Copy link

pantomath91 commented Apr 12, 2021

This is nice but solution will not work if we have more than the three arguments

Loading

@anubhavsrivastava
Copy link
Author

anubhavsrivastava commented Apr 12, 2021

@pantomath91 what have you tried and what is not working?

Loading

@sourabhbit
Copy link

sourabhbit commented Jul 13, 2021

@anubhavsrivastava Actually @pantomath91 is asking if we have to find
add(1,2)(3,3)(4,5,6,8,9)

Can you please help me with this?

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment