Skip to content

Instantly share code, notes, and snippets.

@romerobrjp
Created September 12, 2020 22:55
Show Gist options
  • Save romerobrjp/908c7bb3da55b790f87411c403e9b54c to your computer and use it in GitHub Desktop.
Save romerobrjp/908c7bb3da55b790f87411c403e9b54c to your computer and use it in GitHub Desktop.
Solution for fibonacci using the memoization technique
fibonacci function(n, cache) {
cache = cache || {};
if (n === 0) return 0;
if (n === 1) return 1;
if (cache[n]) return cache[n];
return cache[n] = this.fibonacci(n - 1, cache) + this.fibonacci(n - 2, cache);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment