Skip to content

Instantly share code, notes, and snippets.

@selfup
Created July 25, 2017 18:00
Show Gist options
  • Select an option

  • Save selfup/25eb80f58f63b4d6fb3e544e4381e59b to your computer and use it in GitHub Desktop.

Select an option

Save selfup/25eb80f58f63b4d6fb3e544e4381e59b to your computer and use it in GitHub Desktop.
function fib(n, cache) {
cache = cache || {};
if (n < 2) {
return n;
} else {
if (cache[n]) {
return cache[n]
} else {
cache[n] = fib(n - 1, cache) + fib(n - 2, cache);
return cache[n];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment