JavaScript Memoization Reviewd

Needed to refresh my memory on memoization, so here is a quick example showing memoization for calculating the n-th term of a fibonacci sequence:

Basically we are “caching” the previously calculated values so we don’t end up repeating the same stack call. Implement this recursively with a large value of n and see what happens:

function fibo (n) {
return (!n || n === 1) ? 1 : fibo(n-1) + fibo(n-1);
}

The call stack will grow like a tree, not good …