Basic Algorithm Scripting - Return Largest Numbers in Arrays

Tell us what’s happening:

This solution completed the challenge, but I don’t think it was a good answer. Can someone tell me about the flaws in the way I code?

Your code so far

function largestOfFour(arr) {
  let result = []
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr[i].length; j++) {
      result.push(Math.max(...arr[i]))
      break;
    }
  }
  return result;
}

const output = largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
console.log(output)

Challenge: Basic Algorithm Scripting - Return Largest Numbers in Arrays

Link to the challenge:

Why exactly do you think it’s not a good answer? Do you have some specific concerns? Answering yourself these questions can give you something concrete to focus on.

I think the way I came up with that solution shows I’m not that confident in my answer, though we all know there is no perfect answer or code. I feel it was not enough, or there is something wrong with it.

We have blurred this solution (with [spoiler][/spoiler] tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

Try doing this without the second loop.