Skip to content

Instantly share code, notes, and snippets.

@gorkemozkan
Created September 18, 2023 19:24
Show Gist options
  • Save gorkemozkan/b29467d27d89dd330576b5bed19605c7 to your computer and use it in GitHub Desktop.
Save gorkemozkan/b29467d27d89dd330576b5bed19605c7 to your computer and use it in GitHub Desktop.
Memoize
function memoize(callback) {
const cache = new Map();
return (...args) => {
const strArgs = String(args)
if (cache.has(strArgs)) {
return String(cache.get(strArgs));;
}
const result = callback(...args);
cache.set(strArgs, result);
return result;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment