|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
668 bytes
|
| Line | |
|---|
| 1 | import { unzip } from '../../array/unzip.mjs';
|
|---|
| 2 | import { isArray } from '../predicate/isArray.mjs';
|
|---|
| 3 | import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function unzipWith(array, iteratee) {
|
|---|
| 6 | if (!isArrayLikeObject(array) || !array.length) {
|
|---|
| 7 | return [];
|
|---|
| 8 | }
|
|---|
| 9 | const unzipped = isArray(array) ? unzip(array) : unzip(Array.from(array, value => Array.from(value)));
|
|---|
| 10 | if (!iteratee) {
|
|---|
| 11 | return unzipped;
|
|---|
| 12 | }
|
|---|
| 13 | const result = new Array(unzipped.length);
|
|---|
| 14 | for (let i = 0; i < unzipped.length; i++) {
|
|---|
| 15 | const value = unzipped[i];
|
|---|
| 16 | result[i] = iteratee(...value);
|
|---|
| 17 | }
|
|---|
| 18 | return result;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | export { unzipWith };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.