Travis build: 1370

This commit is contained in:
30secondsofcode
2018-01-24 10:37:02 +00:00
parent f16c0ee8bb
commit d0885d1322
3 changed files with 42 additions and 2 deletions

View File

@ -145,6 +145,7 @@ average(1, 2, 3);
* [`unionBy`](#unionby)
* [`unionWith`](#unionwith)
* [`uniqueElements`](#uniqueelements)
* [`unzip`](#unzip)
* [`without`](#without)
* [`zip`](#zip)
* [`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)
### 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
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

View File

@ -10,7 +10,7 @@ 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)),
length: Math.max(...arr.map(x => x.length))
}).map(x => [])
);
```