Created
May 6, 2024 11:23
-
-
Save srikiranvelpuri/fa9c01c92e217d9db88eda2e704da410 to your computer and use it in GitHub Desktop.
A JavaScript function to cache the results of a function, minimizing redundant computations.
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
const memoize = (f) => | |
function(...args) { | |
f.memoize = f.memoize || {} | |
return args in f.memoize | |
? f.memoize[args] | |
: (f.memoize[args] = f.apply(this, args)) | |
} | |
export default memoize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment