Arrays.zip()
Syntax
function zip(source: unknown[], ...arrays: unknown[][]): TransformedArrays
Combines two or more arrays, creating a new two-dimensional array where each element is a tuple of each element at that index.
Parameters | |
source
|
The first array to combine. |
arrays
Rest
|
The other arrays to combine with |
Example
import { Arrays } from 'potence';
const strings = ['apple', 'banana', 'orange'];
const stringLengths = strings.map(string => string.length);
Arrays.zip(strings, stringLengths);
// Result:
// [
// ['apple', 5],
// ['banana', 6],
// ['orange', 6]
// ]
Remarks
Note: For the sake of simplicity, the above function signature is an abridged version of the function’s real signature. To ensure proper TypeScript typing—especially in regards to the return type—a slightly more complex function signature is needed than what is shown here.