let a = carry(sum)(1)(2);
console.log(a(3)) -> 6
console.log(a(8)) -> 11
sum
может оказаться n-число аргументовconst sum = (a, b, c) => a + b + c
function carry(fn, argsCount=null, baseArgs=[]){
argsCount = argsCount === null ? fn.length : argsCount
if(baseArgs.length >= argsCount){
return fn.apply(null, baseArgs)
}
return function(...args){
return carry(fn, argsCount, baseArgs.concat(args))
}
}
let a = carry(sum)
let b = a(1)(2)
console.log(b(3)) //6
console.log(b(10)) //13