Modified zip to use spread operator instead of Array.apply
This commit is contained in:
@ -6,7 +6,7 @@ If lengths of the argument-arrays vary, `undefined` is used where no value could
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const zip = (...arrays) => {
|
const zip = (...arrays) => {
|
||||||
const maxLength = Math.max.apply(null, arrays.map(a => a.length));
|
const maxLength = Math.max(...arrays.map(x => x.length));
|
||||||
return Array.from({length: maxLength}).map((_, i) => {
|
return Array.from({length: maxLength}).map((_, i) => {
|
||||||
return Array.from({length: arrays.length}, (_, k) => arrays[k][i]);
|
return Array.from({length: arrays.length}, (_, k) => arrays[k][i]);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user