Travis build: 1665
This commit is contained in:
48
README.md
48
README.md
@ -98,6 +98,8 @@ average(1, 2, 3);
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`bifurcate`](#bifurcate)
|
||||
* [`bifurcateBy`](#bifurcateby)
|
||||
* [`chunk`](#chunk)
|
||||
* [`compact`](#compact)
|
||||
* [`countBy`](#countby)
|
||||
@ -761,6 +763,52 @@ const unary = fn => val => fn(val);
|
||||
---
|
||||
## 📚 Array
|
||||
|
||||
### bifurcate
|
||||
|
||||
Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
|
||||
|
||||
Use `Array.reduce()` and `Array.push()` to add elements to groups, based on `filter`.
|
||||
|
||||
```js
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### bifurcateBy
|
||||
|
||||
Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.
|
||||
|
||||
Use `Array.reduce()` and `Array.push()` to add elements to groups, based on the value returned by `fn` for each element.
|
||||
|
||||
```js
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### chunk
|
||||
|
||||
Chunks an array into smaller arrays of a specified size.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -6,12 +6,9 @@ Use `Array.reduce()` and `Array.push()` to add elements to groups, based on `fil
|
||||
|
||||
```js
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
```js
|
||||
bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
|
||||
@ -6,12 +6,9 @@ Use `Array.reduce()` and `Array.push()` to add elements to groups, based on the
|
||||
|
||||
```js
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
```js
|
||||
bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user