Z komentarza:
rather than wrap the sumBelowRect body into an anonymous function, I’d simplify it with a .bind(), like so:
const sumBelowRec = (number, sum = 0) => ( number === 0 ? sum : sumBelowRec.bind(null, number — 1, sum + number) )
var trampoline - function(fn) {
return function() {
var result = fn.apply(null, arguments);
while (typeof result === 'function') {
result = result();
}
return result;
}
}
function doSomething(number, sum) {
var x = sum || 0;
return number === 0 ? x : function() {
return doSomething(number -1, x + number);
}
}
var checkAll = trampoline(doSomething);
doSomething(10);