zipWith
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 using a custom combiner function.
This function takes multiple arrays and a combiner function, and returns a new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of elements in the first array. |
R |
The type of elements in the resulting array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr1 |
readonly T[] |
The first array to zip. |
combine |
(item, index) => R |
The combiner function that takes corresponding elements from each array, their index, and returns a single value. |
Returns
R[]
A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.
Examples
// Example usage with two arrays:
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const result = zipWith(arr1, arr2, (a, b) => a + b);
// result will be [5, 7, 9]
// Example usage with three arrays:
const arr1 = [1, 2];
const arr2 = [3, 4];
const arr3 = [5, 6];
const result = zipWith(arr1, arr2, arr3, (a, b, c) => `${a}${b}${c}`);
// result will be [`135`, `246`]
Call Signature
Combines two arrays into a single array using a custom combiner function.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of elements in the first array. |
U |
The type of elements in the second array. |
R |
The type of elements in the resulting array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr1 |
readonly T[] |
The first array to zip. |
arr2 |
readonly U[] |
The second array to zip. |
combine |
(item1, item2, index) => R |
The combiner function that takes corresponding elements from each array, their index, and returns a single value. |
Returns
R[]
A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.
Call Signature
Combines three arrays into a single array using a custom combiner function.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of elements in the first array. |
U |
The type of elements in the second array. |
V |
The type of elements in the third array. |
R |
The type of elements in the resulting array. |
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. |
combine |
(item1, item2, item3, index) => R |
The combiner function that takes corresponding elements from each array, their index, and returns a single value. |
Returns
R[]
A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.
Call Signature
Combines four arrays into a single array using a custom combiner function.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of elements in the first array. |
U |
The type of elements in the second array. |
V |
The type of elements in the third array. |
W |
The type of elements in the fourth array. |
R |
The type of elements in the resulting array. |
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. |
combine |
(item1, item2, item3, item4, index) => R |
The combiner function that takes corresponding elements from each array, their index, and returns a single value. |
Returns
R[]
A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.