Travis build: 707 [ci skip]
This commit is contained in:
30
README.md
30
README.md
@ -126,6 +126,7 @@
|
|||||||
* [`compose`](#compose)
|
* [`compose`](#compose)
|
||||||
* [`curry`](#curry)
|
* [`curry`](#curry)
|
||||||
* [`functionName`](#functionname)
|
* [`functionName`](#functionname)
|
||||||
|
* [`memoize`](#memoize)
|
||||||
* [`runPromisesInSeries`](#runpromisesinseries)
|
* [`runPromisesInSeries`](#runpromisesinseries)
|
||||||
* [`sleep`](#sleep)
|
* [`sleep`](#sleep)
|
||||||
|
|
||||||
@ -2176,6 +2177,35 @@ functionName(Math.max); // max (logged in debug channel of console)
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### memoize
|
||||||
|
|
||||||
|
Returns the memoized (cached) function.
|
||||||
|
|
||||||
|
Use `Object.create(null)` to create an empty object without `Object.prototype` (so that those properties are not resolved if the input value is something like `'hasOwnProperty'`).
|
||||||
|
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.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const memoize = fn => {
|
||||||
|
const cache = Object.create(null);
|
||||||
|
return value => cache[value] || (cache[value] = fn(value));
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
// See the `anagrams` snippet.
|
||||||
|
const anagramsCached = memoize(anagrams);
|
||||||
|
anagramsCached('javascript'); // takes a long time
|
||||||
|
anagramsCached('javascript'); // returns virtually instantly since it's now cached
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### runPromisesInSeries
|
### runPromisesInSeries
|
||||||
|
|
||||||
Runs an array of promises in series.
|
Runs an array of promises in series.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user