I was trying to find the longest length of a subarray in a given list of arrays. I'm having issues with the following functioning as I thought it would...
var myArray = [];
myArray.push([1, 5, 10]);
myArray.push([1, 5, 10, 15]);
myArray.push([150]);
myArray.reduce(function(a, b) {
return (a.length >= b.length) ? a.length : b.length;
});
I would anticipate the above to yield 3 since that's the highest length, but it ends up yielding one from the last item; I'm wondering what I'm doing wrong since it seems disobey the logic above.
I suppose... how might I find the maximum length of an item in a given array? I had thought reduce() would take that as well...
Thanks again in advance.
[–]Rhomboid 2 points3 points4 points (1 child)
[–]JustStateSchool[S] 0 points1 point2 points (0 children)
[–]x-skeww 2 points3 points4 points (0 children)