Update snippet descriptions
This commit is contained in:
@ -13,8 +13,10 @@ Returns the memoized (cached) function.
|
||||
```js
|
||||
const memoize = fn => {
|
||||
const cache = new Map();
|
||||
const cached = function(val) {
|
||||
return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val);
|
||||
const cached = function (val) {
|
||||
return cache.has(val)
|
||||
? cache.get(val)
|
||||
: cache.set(val, fn.call(this, val)) && cache.get(val);
|
||||
};
|
||||
cached.cache = cache;
|
||||
return cached;
|
||||
@ -25,6 +27,6 @@ const memoize = fn => {
|
||||
// See the `anagrams` snippet.
|
||||
const anagramsCached = memoize(anagrams);
|
||||
anagramsCached('javascript'); // takes a long time
|
||||
anagramsCached('javascript'); // returns virtually instantly since it's now cached
|
||||
anagramsCached('javascript'); // returns virtually instantly since it's cached
|
||||
console.log(anagramsCached.cache); // The cached anagrams map
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user