update snippets 0-All

This commit is contained in:
Stefan Feješ
2017-12-25 14:49:52 +01:00
committed by Agamemnon Zorbas
parent 39164e9cbf
commit e7e687f60c
33 changed files with 166 additions and 74 deletions

View File

@ -10,9 +10,12 @@ If lengths of the argument-arrays vary, `undefined` is used where no value could
const zip = (...arrays) => {
const maxLength = Math.max(...arrays.map(x => x.length));
return Array.from({length: maxLength}).map((_, i) => {
return Array.from({length: arrays.length}, (_, k) => arrays[k][i]);
});
};
// zip(['a', 'b'], [1, 2], [true, false]); -> [['a', 1, true], ['b', 2, false]]
// zip(['a'], [1, 2], [true, false]); -> [['a', 1, true], [undefined, 2, false]]
return Array.from({length: arrays.length}, (_, k) => arrays[k][i]);
})
}
```
```js
zip(['a', 'b'], [1, 2], [true, false]); // [['a', 1, true], ['b', 2, false]]
zip(['a'], [1, 2], [true, false]); // [['a', 1, true], [undefined, 2, false]]
```