Stuck on "Return Largest Numbers in Arrays"

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?

One approach to this could be something like this:

  1. create an array that will hold your final result i.e. resultsArray
  2. loop through each array and pick the largest value (Math.max() could help you with this)
  3. push the value to the resultsArray and return it