function add() {
let args = [].slice.call(arguments);
let sum = function() {
let arg = [].slice.call(arguments);
return add.apply(null, [...args, ...arg]);
}
sum.toString = function() {
return args.reduce((a, b) => a + b);
}
return sum;
}
console.log(add(2, 3)(4)(5)()(1)); // 15