Last active
May 26, 2018 00:14
-
-
Save collinschaafsma/3828517e1546ba65c0ed9104abb72625 to your computer and use it in GitHub Desktop.
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
// cache any function call, use the args as a key | |
const memoize = (fn) => { | |
let cache = {}; | |
return (...args) => { | |
if (cache[args]) { | |
return cache[args]; | |
} else { | |
let result = fn.apply(this, args); | |
cache[args] = result; | |
return result; | |
} | |
} | |
} | |
// const fastFn = memoize(slowFn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment