Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anubhavsrivastava/d02e115f321de4852942c31627e33e0d to your computer and use it in GitHub Desktop.
Save anubhavsrivastava/d02e115f321de4852942c31627e33e0d to your computer and use it in GitHub Desktop.
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

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

@anubhavsrivastava
Copy link
Author

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

@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?

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