Skip to content

Instantly share code, notes, and snippets.

@andrewbonnington
Created November 22, 2016 19:55
Show Gist options
  • Select an option

  • Save andrewbonnington/5111855730389ac119a70e2cfd3578fd to your computer and use it in GitHub Desktop.

Select an option

Save andrewbonnington/5111855730389ac119a70e2cfd3578fd to your computer and use it in GitHub Desktop.
Memoized fibonacci calculation
function fibonacci(n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (fibonacci.cache[n] > 0) return fibonacci.cache[n];
return fibonacci.cache[n] = fibonacci(n - 1) + fibonacci(n - 2);
}
fibonacci.cache = [];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment