UNPKG

es-next-tools

Version:

A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.

16 lines (15 loc) 519 B
/** * Combines two arrays into an array of pairs. * @param {T[]} array - The first array. * @param {U[]} otherArray - The second array to zip with the first array. * @returns {[T, U][]} An array of pairs combining elements from both arrays. * @template T, U * @example * const arr1 = [1, 2, 3]; * const arr2 = ['a', 'b', 'c']; * const zipped = zip(arr1, arr2); // [[1, 'a'], [2, 'b'], [3, 'c']] */ export function zip(array, otherArray) { return array.map((item, index) => [item, otherArray[index]]); } ;