Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Created September 6, 2025 15:04
Show Gist options
  • Select an option

  • Save Slackwise/4101075968d5cb516993d383bd7955d2 to your computer and use it in GitHub Desktop.

Select an option

Save Slackwise/4101075968d5cb516993d383bd7955d2 to your computer and use it in GitHub Desktop.
Simplest memoization function in JavaScript using the latest available syntax.
const memo = f => {
let cache = {};
return (...args) => {
let key = JSON.stringify(args);
return cache[key] ?? (cache[key] = f(...args));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment