How can we make dynamic multiple bracket functions.
function addThis(x){
return function(y){
return x+y;
}
}
addThis(3)(4) // 7
addThis(3)(4)(5) //12
addThis(3)(4)(5)(6) //18
addThis(1)(1)(1)(1)(1) //5
With single bracket function I could achieve something like that using rest parameter.
function add(...args) {
let sum = 0;
for(let i=0; i<args.length; i++) {
sum = sum + args[i];
}
return sum;
}
How can we achieve same with multiple bracket functions.