Created
September 18, 2023 19:24
-
-
Save gorkemozkan/b29467d27d89dd330576b5bed19605c7 to your computer and use it in GitHub Desktop.
Memoize
This file contains 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
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