Created
February 27, 2021 04:49
-
-
Save eengineergz/c15feb228a51a3543625009c8fd0b6de to your computer and use it in GitHub Desktop.
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
function fastFib(n, memo = {}) { | |
if (n in memo) return memo[n]; | |
if (n === 1 || n === 2) return 1; | |
memo[n] = fastFib(n - 1, memo) + fastFib(n - 2, memo); | |
return memo[n]; | |
} | |
fastFib(6); // => 8 | |
fastFib(50); // => 12586269025 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment