Hello everyone,
Need some feedback on this challenge. I am trying to pull the largest number from each sub-array. I know at the end I need a final array that pulls all the largest values. But in the meantime, I am just concatenating the largest values from each of the sub-arrays just to see the “If” statement makes sense. I noticed that the largest value out of all the sub-arrays will stop the concatenation when it’s in the middle of the array, leaving out the rest of the sub-arrays that come after it.
How do I pull all the largest values into the concatenation without breaking the iteration?
Thanks!
Code below:
function largestOfFour(arr) {
var a = 0;
var b = 0;
var total = 0;
var runningNumber = 0;
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
b = arr[i][j];
if (b > a) {
a = b;
total += "" + a ;
} // end of if statement
} //end of inner loop
} //end of outer for loop
return total ;
}//end of function
largestOfFour([[3,2], [12,4], [5,6,7]]);