set10

Fibonacci, but with a cache

10 / 26
read the snippet · pick its Big-O
function fib(n, memo = {}) {
if (n <= 1) return n;
if (memo[n] != null) return memo[n];
return memo[n] = fib(n - 1, memo) + fib(n - 2, memo);
}