Created
July 25, 2017 18:00
-
-
Save selfup/25eb80f58f63b4d6fb3e544e4381e59b to your computer and use it in GitHub Desktop.
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
| 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