Tell us what’s happening:
Challenge: Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
Only the first array seems to have been sorted.
The result I’m getting is [5,13,32,1000]
Your code so far
function largestOfFour(arr) {
for (var i = 0; i < 4; i++){
arr[i].sort(function(a,b){
return b > a;
});
var newArr = [arr[0][0], arr[1][0], arr[2][0], arr[3][0]];
return newArr;
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/return-largest-numbers-in-arrays