Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
Created February 1, 2017 15:35
Show Gist options
  • Save FreeFly19/880189bc22c918cef1096d2c76a245e8 to your computer and use it in GitHub Desktop.
Save FreeFly19/880189bc22c918cef1096d2c76a245e8 to your computer and use it in GitHub Desktop.
Fib with caching
var fibonacci = (function () {
var cache = [];
return function fibo(n) {
if (cache[n]) return cache[n];
return cache[n] = n == 0 ? 0 :
n == 1 ? 1 :
fibo(n-1) + fibo(n-2);
};
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment