Skip to content

Instantly share code, notes, and snippets.

@kylehovey
Created March 27, 2018 19:43
Show Gist options
  • Save kylehovey/30e0382ee3aac5290508a7b641730bff to your computer and use it in GitHub Desktop.
Save kylehovey/30e0382ee3aac5290508a7b641730bff to your computer and use it in GitHub Desktop.
ES6 Memoize Function
function memoize(f) {
const cache = new Map;
return (...args) => {
const key = JSON.stringify(...args);
if (!cache.has(key)) {
cache.set(key, f(...args));
}
return cache.get(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment