Apply new format to snippets and template

This commit is contained in:
Angelos Chalaris
2020-09-15 16:28:04 +03:00
parent 040efd4380
commit 53c16dbf65
401 changed files with 969 additions and 950 deletions

View File

@ -5,9 +5,10 @@ tags: function,advanced
Returns the memoized (cached) function.
Create an empty cache by instantiating a new `Map` object.
Return a function which takes a single argument to be supplied to the memoized function by first checking if the function's output for that specific input value is already cached, or store and return it if not. The `function` keyword must be used in order to allow the memoized function to have its `this` context changed if necessary.
Allow access to the `cache` by setting it as a property on the returned function.
- Create an empty cache by instantiating a new `Map` object.
- Return a function which takes a single argument to be supplied to the memoized function by first checking if the function's output for that specific input value is already cached, or store and return it if not.
- The `function` keyword must be used in order to allow the memoized function to have its `this` context changed if necessary.
- Allow access to the `cache` by setting it as a property on the returned function.
```js
const memoize = fn => {
@ -26,4 +27,4 @@ const anagramsCached = memoize(anagrams);
anagramsCached('javascript'); // takes a long time
anagramsCached('javascript'); // returns virtually instantly since it's now cached
console.log(anagramsCached.cache); // The cached anagrams map
```
```