Skip to content

Instantly share code, notes, and snippets.

@jasonfigueroa
Last active October 26, 2017 20:08
Show Gist options
  • Save jasonfigueroa/4a732137dbb2972b6416a3a4967a9b20 to your computer and use it in GitHub Desktop.
Save jasonfigueroa/4a732137dbb2972b6416a3a4967a9b20 to your computer and use it in GitHub Desktop.
const fibonacci_memo = () => {
const memo = {};
const fibonacci = (n) => {
if (n in memo) {
return memo[n];
} else if (n === 0) {
return 0;
} else if (n <= 2) {
return 1;
}
memo[n] = fibonacci(n - 1) + fibonacci(n - 2);
return memo[n];
};
return fibonacci;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment