Skip to content

Instantly share code, notes, and snippets.

@alanjohnson
Created April 22, 2019 01:02
Show Gist options
  • Save alanjohnson/432d1d6cb1649529f461a5355675e0ea to your computer and use it in GitHub Desktop.
Save alanjohnson/432d1d6cb1649529f461a5355675e0ea to your computer and use it in GitHub Desktop.
memoize function
function memoize(fn) {
const cache = {};
return function(...args) {
if ( cache[args] ) {
return cache[args];
};
const result = fn.apply(this, args);
cache[args] = result;
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment