zip
Import from @varavel/vdl-plugin-sdk/utils/arrays.
Utility functions re-exported from es-toolkit (MIT License).
See https://github.com/toss/es-toolkit for more details.
Call Signature
Combines multiple arrays into a single array of tuples.
This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr1 |
readonly T[] |
The first array to zip. |
Returns
[T][]
A new array of tuples containing the corresponding elements from the input arrays.
Example
Call Signature
Combines multiple arrays into a single array of tuples.
This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements.
Type Parameters
| Type Parameter |
|---|
T |
U |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr1 |
readonly T[] |
The first array to zip. |
arr2 |
readonly U[] |
The second array to zip. |
Returns
[T, U][]
A new array of tuples containing the corresponding elements from the input arrays.
Example
const arr1 = [1, 2, 3];
const arr2 = ['a', 'b', 'c'];
const result = zip(arr1, arr2);
// result will be [[1, 'a'], [2, 'b'], [3, 'c']]
Call Signature
Combines multiple arrays into a single array of tuples.
This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements.
Type Parameters
| Type Parameter |
|---|
T |
U |
V |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr1 |
readonly T[] |
The first array to zip. |
arr2 |
readonly U[] |
The second array to zip. |
arr3 |
readonly V[] |
The third array to zip. |
Returns
[T, U, V][]
A new array of tuples containing the corresponding elements from the input arrays.
Example
const arr1 = [1, 2, 3];
const arr2 = ['a', 'b', 'c'];
const arr3 = [true, false];
const result = zip(arr1, arr2, arr3);
// result will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]]
Call Signature
Combines multiple arrays into a single array of tuples.
This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements.
Type Parameters
| Type Parameter |
|---|
T |
U |
V |
W |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr1 |
readonly T[] |
The first array to zip. |
arr2 |
readonly U[] |
The second array to zip. |
arr3 |
readonly V[] |
The third array to zip. |
arr4 |
readonly W[] |
The fourth array to zip. |
Returns
[T, U, V, W][]
A new array of tuples containing the corresponding elements from the input arrays.
Example
const arr1 = [1, 2, 3];
const arr2 = ['a', 'b', 'c'];
const arr3 = [true, false];
const arr4 = [null, null, null];
const result = zip(arr1, arr2, arr3, arr4);
// result will be [[1, 'a', true, null], [2, 'b', false, null], [3, 'c', undefined, null]]
Call Signature
Combines multiple arrays into a single array of tuples.
This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
...arrs |
readonly T[][] |
The arrays to zip together. |
Returns
T[][]
A new array of tuples containing the corresponding elements from the input arrays.