Skip to content

Instantly share code, notes, and snippets.

@udayvunnam
Last active July 2, 2019 09:04
Show Gist options
  • Save udayvunnam/e0f5348c25d55b0e04392b36c1921470 to your computer and use it in GitHub Desktop.
Save udayvunnam/e0f5348c25d55b0e04392b36c1921470 to your computer and use it in GitHub Desktop.
Memoization to increase performance and cache function execution
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