Skip to content

Instantly share code, notes, and snippets.

@Kadreev
Created March 5, 2022 16:55
Show Gist options
  • Select an option

  • Save Kadreev/2a4d181f310a3a3b96567a3be2de7c54 to your computer and use it in GitHub Desktop.

Select an option

Save Kadreev/2a4d181f310a3a3b96567a3be2de7c54 to your computer and use it in GitHub Desktop.
Caching Memorization
const cache = {}; const myFunc = (input) => { if (cache[input]) { return cache[input]; }; console.log(`calculating...`); const value = input * 2; cache[input] = value; return value; }; myFunc(1); myFunc(2); myFunc(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment