function sumTwo(n) {
let sum = 0;
if (!n) {
return sum;
} else {
return function(n) {
sum += n;
return sumTwo;
}
}
}
console.log(sumTwo(1)(2)(3));
function sum(value) {
return (function next(previousSum) {
return Object.defineProperty(function nextSum(value) {
return next(previousSum + Number(value));
}, 'valueOf', {value() {
return previousSum;
}});
})(Number(value));
}
one = sum(1)
two = one(1)
three = one + two // 3
function sumTwo(n) {
let sum = n;
const f = function(n) {
sum += n;
return f;
}
f.toString = () => {
return sum;
};
return f;
}