zip_longest without fillvalue in typescript I would like to create a function like zip_lognest in python and if the array size is uneven, I do not want to filled any value. following is my code and example

const aFixture = [
  { name: 'name_a', value: 'value_a'},
  { name: 'name_b', value: 'value_b'},
  { name: 'name_c', value: 'value_c'},
  { name: 'name_d', value: 'value_d'},
];
const bFixture = [
  { name: 'name_1', value: 'value_1'},
  { name: 'name_2', value: 'value_2'},
];
const cFixture = [
  { name: 'name_x', value: 'value_x'},
  { name: 'name_y', value: 'value_y'},
  { name: 'name_z', value: 'value_z'},
];
export function zipLongest(...arrays: Array&lt;any&gt;) {
  const length = Math.max(...arrays.map((arr) =&gt; arr.length));
  const tempArray = Array.from({length}, (_, index) =&gt; 
    arrays.map((array) =&gt; (array.length - 1 &gt;= index ? array[index] : undefined))
  )
  return tempArray.map((array) =&gt; array.filter((x: any) =&gt; x !== undefined)) 
}

const myarray =
  zipLongest(
    aFixture,
    bFixture,
    cFixture,
  )
console.log(myarray);
//[ [ { name: 'name_a', value: 'value_a' },
//    { name: 'name_1', value: 'value_1' },
//    { name: 'name_x', value: 'value_x' } ],
//  [ { name: 'name_b', value: 'value_b' },
//    { name: 'name_2', value: 'value_2' },
//    { name: 'name_y', value: 'value_y' } ],
//  [ { name: 'name_c', value: 'value_c' },
//    { name: 'name_z', value: 'value_z' } ],
//  [ { name: 'name_d', value: 'value_d' }, ]
//]
How about this? You iterate through each array only once.

function zipLongest(...arrays: Array&lt;any&gt;) {
    const result:any[] = [];
    arrays.forEach((arr) =&gt; {
      arr.forEach((val: any, i: number) =&gt; { 
        if (i === result.length) result.push([]);
            result[i].push(val);
      })
    });
    return result;
}




"use strict";
const aFixture = [
    { name: 'name_a', value: 'value_a' },
    { name: 'name_b', value: 'value_b' },
    { name: 'name_c', value: 'value_c' },
    { name: 'name_d', value: 'value_d' },
];
const bFixture = [
    { name: 'name_1', value: 'value_1' },
    { name: 'name_2', value: 'value_2' },
];
const cFixture = [
    { name: 'name_x', value: 'value_x' },
    { name: 'name_y', value: 'value_y' },
    { name: 'name_z', value: 'value_z' },
];
function zipLongest(...arrays) {
    const result = [];
    arrays.forEach((arr) =&gt; {
        for (var i = 0; i &lt; arr.length; i++) {
            if (i &gt;= result.length) {
                result.push([arr[i]]);
            }
            else {
                result[i] = result[i].concat(arr[i]);
            }
        }
    });
    return result;
}
const myarray = zipLongest(aFixture, bFixture, cFixture);
console.log(myarray);