- Math.max(): To get the longest array out of all argument arrays.
- Then, create an array with that length as return value and use Array.from() with a mapping function to create an array of grouped elements.
- Array.prototype.map(): To convert every array element into a new array.
- Moreover, the spread operator (…) is used to represent a variable number of arrays that can be passed as arguments in the parameter field of the zip function.
Now let us look at how we can implement unzip:
- Math.max(): Get the longest subarray in the array.
- Array.prototype.map(): Make each array element into an array.
- Array.prototype.reduce() and Array.prototype.forEach(): Map the grouped values to individual arrays.
- Lastly, Array.prototype.map() and the spread operator (…) are used to apply the f parameter in the unzip function to each individual group of elements.