Skip to content

Instantly share code, notes, and snippets.

@iJustErikk
Created December 4, 2020 17:52
Show Gist options
  • Save iJustErikk/23198f2272d1f55847c9a13bd448494e to your computer and use it in GitHub Desktop.
Save iJustErikk/23198f2272d1f55847c9a13bd448494e to your computer and use it in GitHub Desktop.
// 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