Skip to content

Instantly share code, notes, and snippets.

@Bamblehorse
Created April 23, 2018 20:57
Show Gist options
  • Save Bamblehorse/94ea8150d62dec653171f7a5ada6fe92 to your computer and use it in GitHub Desktop.
Save Bamblehorse/94ea8150d62dec653171f7a5ada6fe92 to your computer and use it in GitHub Desktop.
Memoize
// https://mostly-adequate.gitbooks.io/mostly-adequate-guide/ch03.html#the-case-for-purity
const memoize = (f) => {
const cache = {};
return (...args) => {
const argStr = JSON.stringify(args);
cache[argStr] = cache[argStr] || f(...args);
console.log(cache) // added for checking out the cache
return cache[argStr];
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment