Use full name for reduce
This commit is contained in:
10
README.md
10
README.md
@ -34,6 +34,7 @@
|
||||
* [Last of list](#last-of-list)
|
||||
* [Measure time taken by function](#measure-time-taken-by-function)
|
||||
* [Object from key value pairs](#object-from-key-value-pairs)
|
||||
* [Pipe](#pipe)
|
||||
* [Powerset](#powerset)
|
||||
* [Random number in range](#random-number-in-range)
|
||||
* [Randomize order of array](#randomize-order-of-array)
|
||||
@ -327,6 +328,15 @@ const objectFromPairs = arr => arr.reduce((a,b) => (a[b[0]] = b[1], a), {});
|
||||
// objectFromPairs([['a',1],['b',2]]) -> {a: 1, b: 2}
|
||||
```
|
||||
|
||||
### Pipe
|
||||
|
||||
Use `Array.reduce()` to pass value through functions.
|
||||
|
||||
```js
|
||||
const pipe = (...funcs) => arg => funcs.reduce((acc, func) => func(acc), arg);
|
||||
// pipe(btoa, x => x.toUpperCase())("Test") -> "VGVZDA=="
|
||||
```
|
||||
|
||||
### Powerset
|
||||
|
||||
Use `reduce()` combined with `map()` to iterate over elements and combine into an array containing all combinations.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
### Pipe
|
||||
|
||||
Use `reduce()` to pass value through functions.
|
||||
Use `Array.reduce()` to pass value through functions.
|
||||
|
||||
```js
|
||||
const pipe = (...funcs) => arg => funcs.reduce((acc, func) => func(acc), arg);
|
||||
|
||||
Reference in New Issue
Block a user