JavaScript Challenge:
function findLargestInEachSubArray(arr) {
var maxValue = 0;
var largestNumbers = [];
for(var i = 0; i < arr.sort().reverse().length; i++){
for(var j = 0; j < arr[i].length; j++){
if(maxValue < arr[i][j]){
maxValue = arr[i][j]; // issue here
//largestNumbers.push(maxValue); this will only add the first element in each subset
// result [4,5,13,27,32,35,37,39,1000,1001]
}
}
}
return largestNumbers;
}
findLargestInEachSubArray([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
// Expected Outcome:
// [5, 27, 39, 1001]
I'm stuck on this problem. How can I modify my function to correctly find and store the biggest number from each sub-array into the largestNumbers
array using nested for-loops?