Skip to content

Instantly share code, notes, and snippets.

@st32lthx
Created November 4, 2015 02:36
Show Gist options
  • Save st32lthx/6943bd19a023e4b4b303 to your computer and use it in GitHub Desktop.
Save st32lthx/6943bd19a023e4b4b303 to your computer and use it in GitHub Desktop.
Simple Memoization Example in JavaScriopt
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;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment