Created
September 6, 2025 15:04
-
-
Save Slackwise/4101075968d5cb516993d383bd7955d2 to your computer and use it in GitHub Desktop.
Simplest memoization function in JavaScript using the latest available syntax.
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 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