Created
September 12, 2020 22:55
-
-
Save romerobrjp/908c7bb3da55b790f87411c403e9b54c to your computer and use it in GitHub Desktop.
Solution for fibonacci using the memoization technique
This file contains hidden or 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
fibonacci function(n, cache) { | |
cache = cache || {}; | |
if (n === 0) return 0; | |
if (n === 1) return 1; | |
if (cache[n]) return cache[n]; | |
return cache[n] = this.fibonacci(n - 1, cache) + this.fibonacci(n - 2, cache); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment