|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
407 bytes
|
| Line | |
|---|
| 1 | function zipWith(arr1, ...rest) {
|
|---|
| 2 | const arrs = [arr1, ...rest.slice(0, -1)];
|
|---|
| 3 | const combine = rest[rest.length - 1];
|
|---|
| 4 | const maxIndex = Math.max(...arrs.map(arr => arr.length));
|
|---|
| 5 | const result = Array(maxIndex);
|
|---|
| 6 | for (let i = 0; i < maxIndex; i++) {
|
|---|
| 7 | const elements = arrs.map(arr => arr[i]);
|
|---|
| 8 | result[i] = combine(...elements, i);
|
|---|
| 9 | }
|
|---|
| 10 | return result;
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | export { zipWith };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.