Created
February 17, 2016 21:17
-
-
Save zzarcon/d4bea4fb85f317fe8fc1 to your computer and use it in GitHub Desktop.
Javascript Fibonacci memoization
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 fibonacci(num, memo) { | |
memo = memo || {}; | |
if (memo[num]) return memo[num]; | |
if (num <= 1) return 1; | |
return memo[num] = fibonacci(num - 1, memo) + fibonacci(num - 2, memo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TS Fibonacci memoization
Output:
https://github.com/syedwshah/fibonacci_memoization.ts
https://repl.it/@SyedShah7/CoarseUnsteadyMethod#index.ts
Personally, I think this is better: