Last active
May 10, 2018 10:15
-
-
Save andycarrell/46193428fb1ab557e3416fd321115c97 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 cached = fn => { | |
const c = Object.create(null); | |
return a => { | |
if (a in c) return c[a]; | |
const value = fn(a); | |
c[a] = value; | |
return value; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment