Created
December 4, 2020 17:52
-
-
Save iJustErikk/23198f2272d1f55847c9a13bd448494e 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
// map supports has(key), get(key) and set(key, val) | |
const fib = (n, memo = new Map()) => { | |
if (memo.has(n)) return memo.get(n); | |
if (n <= 1) return 1; | |
memo.set(n, fib(n-1, memo) + fib(n-2, memo)); | |
return memo.get(n); | |
}; | |
for(let i = 0; i <= 1476; i++) { | |
console.log(i, fib(i)); | |
} | |
// fib(1476 is Infinity for js) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment