Created
April 22, 2019 01:02
-
-
Save alanjohnson/432d1d6cb1649529f461a5355675e0ea to your computer and use it in GitHub Desktop.
memoize function
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(fn) { | |
const cache = {}; | |
return function(...args) { | |
if ( cache[args] ) { | |
return cache[args]; | |
}; | |
const result = fn.apply(this, args); | |
cache[args] = result; | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment