Last active
October 26, 2017 20:08
-
-
Save jasonfigueroa/4a732137dbb2972b6416a3a4967a9b20 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
const fibonacci_memo = () => { | |
const memo = {}; | |
const fibonacci = (n) => { | |
if (n in memo) { | |
return memo[n]; | |
} else if (n === 0) { | |
return 0; | |
} else if (n <= 2) { | |
return 1; | |
} | |
memo[n] = fibonacci(n - 1) + fibonacci(n - 2); | |
return memo[n]; | |
}; | |
return fibonacci; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment