Created
May 11, 2021 02:05
-
-
Save carmandomx/e3a68ecebec53dcbb2308b26c4af57e2 to your computer and use it in GitHub Desktop.
fib.js
This file contains 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 fib = (pos, memos) => { | |
if (pos === 0) { | |
return 0 | |
} | |
if (pos === 1) { | |
return 1 | |
} | |
if (memos[pos] !== undefined) { | |
return memos[pos] | |
} | |
memos[pos] = fib(pos - 1, memos) + fib(pos - 2, memos) | |
return memos[pos] | |
} | |
console.log(fib(1000, {})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment