es-toolkit/docs/reference/array/unzipWith.md
Dongkyu Kim 834d50c389
feat(unzipWith): add unzipWith (#113)
* feat(array): add unzipWith

* docs(array): add unzipWith reference

* perf: refactoring unzipWith bench

* docs(array): add vitepress

* Apply suggestions from code review

* Update unzipWith.ts

* Update src/array/unzipWith.ts

* Update benchmarks/unzipWith.bench.ts

* Update benchmarks/unzipWith.bench.ts

* Update src/array/unzipWith.spec.ts

* Update src/array/unzipWith.spec.ts

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
Co-authored-by: Sojin Park <raon0211@toss.im>
2024-07-03 10:40:33 +09:00

697 B

unzipWith

Unzips an array of arrays, applying an iteratee function to regrouped elements.

Signature

function unzipWith<T, R>(target: T[][], iteratee: (...args: T[]) => R): R[];

Parameters

  • target(T[][]): The nested array to unzip. This is an array of arrays, where each inner array contains elements to be unzipped.
  • iteratee ((...args: T[]) => R): A function to transform the unzipped elements.

Returns

(R[]): A new array of unzipped and transformed elements.

Examples

const nestedArray = [
  [1, 2],
  [3, 4],
  [5, 6],
];
const result = unzipWith(nestedArray, (item, item2, item3) => item + item2 + item3);
// [9, 12]