Skip to content

Instantly share code, notes, and snippets.

@jasonwaters
Created January 27, 2017 18:06
Show Gist options
  • Select an option

  • Save jasonwaters/348db35ab01df68bea8cd4789dbeafa0 to your computer and use it in GitHub Desktop.

Select an option

Save jasonwaters/348db35ab01df68bea8cd4789dbeafa0 to your computer and use it in GitHub Desktop.
memoize function
function memoized(fn) {
let cache = {};
return function(key) {
if(typeof cache[key] !== 'undefined') {
return cache[key];
}else {
let result = fn.apply(null, arguments);
cache[key] = result;
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment