Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created December 15, 2015 22:15
Show Gist options
  • Save lovasoa/9f34fd270cac31ee8bb3 to your computer and use it in GitHub Desktop.
Save lovasoa/9f34fd270cac31ee8bb3 to your computer and use it in GitHub Desktop.
Memoization implementation in javascript
function memoize(f) {
var dict = {};
return function() {
var args = JSON.stringify(arguments);
if(dict.hasOwnProperty(args)) return dict[args];
var res = f.apply(null, arguments);
dict[args] = res;
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment