Created
March 24, 2017 06:59
-
-
Save ivan-ha/3b766cd1128e5d35136bb43715740f85 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
| var fibonacci = function(number) { | |
| var mem = {}; | |
| function f(n) { | |
| var value; | |
| if (n in mem) { | |
| value = mem[n]; | |
| } | |
| else { | |
| if (n === 0 || n === 1) | |
| value = n; | |
| else | |
| value = f(n - 1) + f(n - 2); | |
| mem[n] = value; | |
| } | |
| return value; | |
| } | |
| return f(number); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment