Variadic curried sum function
Not sure if I understood what you want, but
function sum(n) {
var v = function(x) {
return sum(n + x);
};
v.valueOf = v.toString = function() {
return n;
};
return v;
}
console.log(+sum(1)(2)(3)(4));
JsFiddle
This is an example of using empty brackets in the last call as a close key (from my last interview):
sum(1)(4)(66)(35)(0)()
function sum(numberOne) {
var count = numberOne;
return function by(numberTwo) {
if (numberTwo === undefined) {
return count;
} else {
count += numberTwo;
return by;
}
}
}
console.log(sum(1)(4)(66)(35)(0)());