Last active: 2 years ago
Sum with an arbitray amount of brackets
function sum(a) {
let currentSum = a;
function f(b) {
currentSum += b;
return f;
}
f.toString = function () {
return currentSum;
};
f[Symbol.toPrimitive] = function () {
return currentSum;
};
return f;
}
console.log(sum(1)(2).toString());
function sum(a) {
sum.current = (sum.current ?? 0) + a;
sum.toString = () => sum.current;
return sum;
}
console.log(sum(1)(2).toString());
function sum(a) {
function f(b) {
return sum(a + b);
}
f.toString = () => a
return f;
}
console.log(sum(1)(2).toString());