Travis build: 1370
This commit is contained in:
31
README.md
31
README.md
@ -145,6 +145,7 @@ average(1, 2, 3);
|
|||||||
* [`unionBy`](#unionby)
|
* [`unionBy`](#unionby)
|
||||||
* [`unionWith`](#unionwith)
|
* [`unionWith`](#unionwith)
|
||||||
* [`uniqueElements`](#uniqueelements)
|
* [`uniqueElements`](#uniqueelements)
|
||||||
|
* [`unzip`](#unzip)
|
||||||
* [`without`](#without)
|
* [`without`](#without)
|
||||||
* [`zip`](#zip)
|
* [`zip`](#zip)
|
||||||
* [`zipObject`](#zipobject)
|
* [`zipObject`](#zipobject)
|
||||||
@ -1966,6 +1967,36 @@ uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### unzip
|
||||||
|
|
||||||
|
Creates an array of arrays, ungrouping the elements in an array produced by [zip](#zip).
|
||||||
|
|
||||||
|
Use `Math.max.apply()` to get the longest subarray in the array, `Array.map()` to make each element an array.
|
||||||
|
Use `Array.reduce()` and `Array.forEach()` to map grouped values to individual arrays.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const unzip = arr =>
|
||||||
|
arr.reduce(
|
||||||
|
(acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc),
|
||||||
|
Array.from({
|
||||||
|
length: Math.max(...arr.map(x => x.length))
|
||||||
|
}).map(x => [])
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
unzip([['a', 1, true], ['b', 2, false]]); //[['a', 'b'], [1, 2], [true, false]]
|
||||||
|
unzip([['a', 1, true], ['b', 2]]); //[['a', 'b'], [1, 2], [true]]
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### without
|
### without
|
||||||
|
|
||||||
Filters out the elements of an array, that have one of the specified values.
|
Filters out the elements of an array, that have one of the specified values.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -10,7 +10,7 @@ const unzip = arr =>
|
|||||||
arr.reduce(
|
arr.reduce(
|
||||||
(acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc),
|
(acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc),
|
||||||
Array.from({
|
Array.from({
|
||||||
length: Math.max(...arr.map(x => x.length)),
|
length: Math.max(...arr.map(x => x.length))
|
||||||
}).map(x => [])
|
}).map(x => [])
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user