Skip to content

Instantly share code, notes, and snippets.

@arch-jslin
Created May 17, 2010 03:10
Show Gist options
  • Save arch-jslin/403353 to your computer and use it in GitHub Desktop.
Save arch-jslin/403353 to your computer and use it in GitHub Desktop.
var memoizer = function (memo, fundamental) {
var shell = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = fundamental(shell, n);
memo[n] = result;
}
return result;
};
return shell;
};
//usage example
var fibonacci = memoizer([0, 1], function (shell, n) {
return shell(n - 1) + shell(n - 2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment