I think test for this challenge needs fixing, my code is correct

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**
function largestOfFour(arr) {
let max=arr[0][0];
let i=0;
for ( let a=0; a<arr.length; a++){
  for ( let j=0; j<arr[a].length; j++){
      max = arr[a][j];
      i = a; 


return arr[i];


largestOfFour([[4, 9, 1, 300000], [13, 35, 1800, 26], [32, 350000, 97, 39], [0, 1001, 857, 1]]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

It is a bad habit to assume that your code is perfect and everything else is broken. (But I’d be lying if I said I’ve never been guilty of that.)

largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]) should return [27, 5, 39, 1001] .

You return: [ 1000, 1001, 857, 1 ]

How is that the correct answer?

@kevinSmith How should it return [27, 5, 39, 1001] when there is no such sub-array in initial array?

Always read the instructions closely. When I get a task at work, I read the requirements 3 times, reread them each morning that I’m still working on it, and then reread them again before submitting the code.

Return an array consisting of the largest number from each provided sub-array.

So, the first number should be the largest number from the first array, the second is the largest from the second array, etc. That is what is the instructions are telling you to do and that is what you could also infer from the tests.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.