UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

22 lines (19 loc) 668 B
import { unzip } from '../../array/unzip.mjs'; import { isArray } from '../predicate/isArray.mjs'; import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs'; function unzipWith(array, iteratee) { if (!isArrayLikeObject(array) || !array.length) { return []; } const unzipped = isArray(array) ? unzip(array) : unzip(Array.from(array, value => Array.from(value))); if (!iteratee) { return unzipped; } const result = new Array(unzipped.length); for (let i = 0; i < unzipped.length; i++) { const value = unzipped[i]; result[i] = iteratee(...value); } return result; } export { unzipWith };