Update snippet descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-22 20:24:44 +03:00
parent 5cb69e3c5c
commit aa425812b4
40 changed files with 151 additions and 87 deletions

View File

@ -3,9 +3,9 @@ title: unzipWith
tags: array,advanced
---
Creates an array of elements, ungrouping the elements in an array produced by [zip](#zip) and applying the provided function.
Creates an array of elements, ungrouping the elements in an array produced by [zip](/js/s/zip) and applying the provided function.
- Use `Math.max.apply()` to get the longest subarray in the array, `Array.prototype.map()` to make each element an array.
- Use `Math.max()`, `Function.prototype.apply()` to get the longest subarray in the array, `Array.prototype.map()` to make each element an array.
- Use `Array.prototype.reduce()` and `Array.prototype.forEach()` to map grouped values to individual arrays.
- Use `Array.prototype.map()` and the spread operator (`...`) to apply `fn` to each individual group of elements.
@ -22,5 +22,12 @@ const unzipWith = (arr, fn) =>
```
```js
unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)); // [3, 30, 300]
unzipWith(
[
[1, 10, 100],
[2, 20, 200],
],
(...args) => args.reduce((acc, v) => acc + v, 0)
);
// [3, 30, 300]
```