Created
February 3, 2019 17:35
-
-
Save anubhavsrivastava/d02e115f321de4852942c31627e33e0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 what have you tried and what is not working?
@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
This is nice but solution will not work if we have more than the three arguments