Skip to content

Instantly share code, notes, and snippets.

@gasolin
Created August 28, 2016 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gasolin/80c4a43b40ba80a0482e64efb2fe1b41 to your computer and use it in GitHub Desktop.
Save gasolin/80c4a43b40ba80a0482e64efb2fe1b41 to your computer and use it in GitHub Desktop.
memorize.js
// from https://jigsawye.gitbooks.io/mostly-adequate-guide/content/ch3.html
var memorize = function(f) {
var cache = {};
return function() {
var arg_str = JSON.stringify(arguments);
cache[arg_str] = cache[arg_str] || f.apply(f, arguments)
return cache[arg_str];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment