Created
January 28, 2017 18:08
-
-
Save rinchik/eb0437b8fed27e36dcd4d10a74027f1a to your computer and use it in GitHub Desktop.
FibonacciMemoization.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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