DEV Community

Discussion on: Recursion optimization in JS - where is it? PTC, TCO and FUD

Collapse
elugens profile image
Stacey Wilson

He should change that because it can confuse the noobs.

function fibonacci(num, memo) {
memo = memo || {};

if (memo[num]) return memo[num];
if (num <= 1) return 1;

return memo[num] = fibonacci(num - 1, memo) + fibonacci(num - 2, memo);
}