Created
December 29, 2016 08:58
-
-
Save suhaotian/cb2ba66252f0591d0d49aa158389ca95 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
function cached(fn) { | |
const cache = Object.create(null) | |
return function cachedFn(str) { | |
const hit = cache[str] | |
return hit || (cache[str] = fn(str)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment