Created
November 7, 2019 06:28
-
-
Save mersanuzun/635de84edf346ac46fd757ec0b10c39d to your computer and use it in GitHub Desktop.
Memo for Javascript
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 memo = () => { | |
const cache = {}; | |
return function() { | |
const key = Object.values(arguments).join('_'); | |
if (key in cache) { | |
return cache[key]; | |
}; | |
const result = fn.apply(this, arguments); | |
cache[key] = result; | |
return result; | |
} | |
}; | |
module.exports = memo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment