Skip to content

Instantly share code, notes, and snippets.

@ivan-ha
Created March 24, 2017 06:59
Show Gist options
  • Select an option

  • Save ivan-ha/3b766cd1128e5d35136bb43715740f85 to your computer and use it in GitHub Desktop.

Select an option

Save ivan-ha/3b766cd1128e5d35136bb43715740f85 to your computer and use it in GitHub Desktop.
var fibonacci = function(number) {
var mem = {};
function f(n) {
var value;
if (n in mem) {
value = mem[n];
}
else {
if (n === 0 || n === 1)
value = n;
else
value = f(n - 1) + f(n - 2);
mem[n] = value;
}
return value;
}
return f(number);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment