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

后端 未结 8 2254
醉话见心
醉话见心 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:16

    Sort a list of indexes by length in descending order, and take the first one:

    a.map((e, i) => i) . sort((i, j) => a[j].length - a[i].length) [0]
    

提交回复
热议问题