Find the index of the longest array in an array of arrays

后端 未结 8 2108
醉话见心
醉话见心 2021-02-05 09:44

If you have an array containing an indefinite amount of arrays

ex:

var masterArray = [ [1,2,3,4,5],
                    [1,2], 
                    [1,1,         


        
8条回答
  •  难免孤独
    2021-02-05 10:15

    masterArray.reduce(function(a,i,ii){
      if (ii === 1){
        return a
      };
      if (i.length > a.length){
        return i
      }
      return a
    })

提交回复
热议问题