3 ms·
I can't read the article (silly work web filters), but if you're quoting him correctly then I have an idea. ( function foo(n) { ... return n+foo(n-1)
by Jtsummers 16y ago
I can't read the article (silly work web filters), but if you're quoting him correctly then I have an idea. (
function foo(n) {
...
return n+foo(n-1);
}
is not tail recursive because the last operation is not the recursive function call, but rather the addition.
function bar(n,acc) {
...
return bar(n-1,acc+n);
}
is tail recursive because the last operation is now the recursive function call.