Skip to content

Instantly share code, notes, and snippets.

@juniorbird
Created April 24, 2018 01:23
Show Gist options
  • Save juniorbird/4869babcb9992cbbdfa36c0f64f2ba43 to your computer and use it in GitHub Desktop.
Save juniorbird/4869babcb9992cbbdfa36c0f64f2ba43 to your computer and use it in GitHub Desktop.
Simple JS Memoize
let utils = {};
utils.memoize = function(fn) {
let cache = {};
return function(...args) {
let key = [...args].join(',');
if (cache[key]) return cache[key];
let result = fn(...args);
cache[key] = result;
return result;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment