# 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

It is unique and I like that you are using pop(). You could take this same concept and shorten the code by getting rid of the 2nd arr.map and simply move your final return statement from the bottom to the top as seen below. This way you only iterate over arr one time.

``````function largestOfFour(arr) {
return arr.map(function (val){
val.sort(function (a, b){
return a - b;
});
return val.pop();
});
}
``````
1 Like

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

@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;
});

});
}``````