LendAndRegret/node_modules/es-toolkit/dist/compat/array/unzipWith.mjs
2026-05-02 17:27:43 +08:00

22 lines
668 B
JavaScript

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 };