Created
April 24, 2018 01:23
-
-
Save juniorbird/4869babcb9992cbbdfa36c0f64f2ba43 to your computer and use it in GitHub Desktop.
Simple JS Memoize
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
let utils = {}; | |
utils.memoize = function(fn) { | |
let cache = {}; | |
return function(...args) { | |
let key = [...args].join(','); | |
if (cache[key]) return cache[key]; | |
let result = fn(...args); | |
cache[key] = result; | |
return result; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment