xxxxxxxxxx
const sum = a => b => b? sum(a + b) : a;
console.log(
sum(1)(2)(),
sum(3)(4)(5)()
);
Run code snippet
xxxxxxxxxx
function sum (args) {
return Object.assign(
sum.bind(null, args),
{ valueOf: () => args.reduce((a, c) => a + c, 0) }
)
}
console.log(+sum(1)(2)(3,2,1)(16))