DEV Community

Discussion on: JavaScript find min/max from array of arrays

Collapse
 
mistval profile image
Randall

This is a good solution, but I tend to prefer sorting:

const highest = users.slice().sort((a, b) => b[1] - a[1])[0];
Enter fullscreen mode Exit fullscreen mode

This is actually less efficient than the reduce method though (O(nlogn) vs O(n)) so I would use reduce if the array is VERY large (at least several millions elements).