-
-
Save Kadreev/2a4d181f310a3a3b96567a3be2de7c54 to your computer and use it in GitHub Desktop.
Caching Memorization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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