Skip to content

Instantly share code, notes, and snippets.

@srikiranvelpuri
Created May 6, 2024 11:23
Show Gist options
  • Save srikiranvelpuri/fa9c01c92e217d9db88eda2e704da410 to your computer and use it in GitHub Desktop.
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.
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