Created
April 10, 2020 13:07
-
-
Save Caballerog/f19a688883c9ddd003a26b09c5d37797 to your computer and use it in GitHub Desktop.
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 memoize = fn => { | |
const cache = {}; // 1 | |
return (...args) => { // 2 | |
const stringfiedArgs = JSON.stringify(args); // 3 | |
const result = (cache[stringifiedArgs] = | |
typeof cache[stringifiedargs] === 'undefined' | |
? fn(...args) | |
: cache[stringifedArgs]); // 4 | |
return result; // 5 | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment