Skip to content

Instantly share code, notes, and snippets.

@rinchik
Created January 28, 2017 18:08
Show Gist options
  • Save rinchik/eb0437b8fed27e36dcd4d10a74027f1a to your computer and use it in GitHub Desktop.
Save rinchik/eb0437b8fed27e36dcd4d10a74027f1a to your computer and use it in GitHub Desktop.
FibonacciMemoization.js
var cache = {};
function fibonacci(number) {
if (number < 1)
return 0;
if (number <= 2)
return 1;
if (number in cache)
return cache[number];
var value = fibonacci(number- 1) + fibonacci(number - 2);
cache[number] = value;
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment