Skip to content

Instantly share code, notes, and snippets.

@ajmeyghani
Created August 23, 2018 13:32
Show Gist options
  • Save ajmeyghani/46e68e637021bb797eac4172a34d576e to your computer and use it in GitHub Desktop.
Save ajmeyghani/46e68e637021bb797eac4172a34d576e to your computer and use it in GitHub Desktop.
var fibo = (function () {
var memo = {};
function fi(n) {
if (n < 0) { return -1 } else {
var value = (n in memo) ? memo[n] : (!n || n === 1) ? 1 : fi(n - 1) + fi(n - 2);
memo[n] = value;
return value;
}
}
return fi;
})();
view raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment