Skip to content

Instantly share code, notes, and snippets.

@mersanuzun
Created November 7, 2019 06:28
Show Gist options
  • Save mersanuzun/635de84edf346ac46fd757ec0b10c39d to your computer and use it in GitHub Desktop.
Save mersanuzun/635de84edf346ac46fd757ec0b10c39d to your computer and use it in GitHub Desktop.
Memo for Javascript
const memo = () => {
const cache = {};
return function() {
const key = Object.values(arguments).join('_');
if (key in cache) {
return cache[key];
};
const result = fn.apply(this, arguments);
cache[key] = result;
return result;
}
};
module.exports = memo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment