Completed Return Largest Numbers in Arrays, does this look ok?

Hi all, I’ve just finished this challenge and my code passed fine (yay!).
I’ve done some Googling since to see how others solved this problem and haven’t found anything that resembles my solution and would appreciate any critiques or suggestions as I’m not sure if my answer is ‘good’ or if I’ve just fluked something that happens to pass!

function largestOfFour(arr) {

arr.map(function (val){
    val.sort(function (a, b){
        return a - b;
    });
 });

arr = arr.map(function (val){
  return val.pop();
});

return arr;
}

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

1 Like

Thanks for the feedback. I’ll definitely take that on board for next time :slight_smile:

@StuWares that is a creative use of pop(), it is a good answer.

You want to see how others solved it, here is my solution:

function largestOfFour(arr) {

  // for every array in "arr"
  return arr.map(function(outer) {

    // reduce to the largest value
    return outer.reduce(function(acc, val) {
      return acc > val ? acc : val;
    });

  });
}