Fibonacci using cache This is my simple Fibonacci implementation in CoffeeScript. What do you think?  Using cache (fibResults), it's very very fast. 

fibResults = []
defaultMax = 1000
nrMax = defaultMax

fibonacci = (n) -&gt;
  return fibResults[n] if fibResults[n]

  if n &lt; 2
    fibResults[n] = n
  else
    fibResults[n] = fibonacci(n - 1) + fibonacci(n - 2)

nrMax = process.argv[2] if process.argv[2]

console.log("#{i}: #{fibonacci(i)}") for i in [0..nrMax]
Something I noticed in your algorithm is that despite using memoization, you are still reassigning the Fibonnacci number into the array every time you calculate it. 

You could avoid reassigning by having a function like computeIfAbsent that determines if the Fibonacci for a given n has already been calculated, and if not, use the Fibonacci function to calculate it and put it into the array, but only this time.

Also, we could avoid having to calculate the first two Fibonaccis by having them memoized from the start, and make the code fail for any index n smaller than 0.

memo = [0,1]

computeIfAbsent = (n, f) -&gt;
    fib = memo[n]
    if typeof fib is 'undefined'
        fib = f(n)
        memo[n] = fib
    fib

fibonacci = (x) -&gt;
    if x &lt; 0 
        throw Error("Invalid index: " + x)
    computeIfAbsent(x, (n) -&gt; fibonacci(n-1) +  fibonacci(n-2))

console.log("#{i}: #{fibonacci(i)}") for i in [0..79]


Still, you must be aware that this code will not detect arithmetic overflows. It might look like it is calculating it right, but in fact, the calculations could be wrong due to overflow. I think your version and mine start to produce invalid results around 79.

You can check using a Fibonacci Calculator