Anything wrong with this solution?

I see a lot of people are using math.max and/or nested for loops, is my approach to this challenge wrong? is it less efficient?
edit: my solution worked and did solve the problem

Any thoughts are appreciated.


function largestOfFour(arr) {
let largest = [];
for (let elem of arr) {
  elem.sort(function(a, b){return b-a});
  largest.push(elem[0])
}
return largest;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

Personally, I don’t like approaches that change the input data.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.