Hey guys, I’m looking for some tips or advice to help me get past this challenge. I am really trying to complete these algorithm challenges without looking at the final solution unless I really need to. This one I have been stuck on for several hours.
function largestOfFour(arr) {
var largestNum = 0;
var largestArr;
for (var i = 0 ; i < arr.length ; i++) {
for (var j = 0 ; j < arr[i].length ; j++){
if (arr[i][j] > largestNum){
largestNum = arr[i][j];
largestArr = arr[i];
}
}
}
return largestArr;
}
Originally, I question kinda through me off at first. So now I have the function returning the array with the largest value, rather than having it return the largest value from each array into a new array.
What do I need to include here? I am assuming I need to create an empty array variable and use some array method such as push to push each element with the large value into a new array and then return that new array?