The first solution I commented doesn't work. Why?!

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

The first code I wrote it here, works well and outputs the result in the console correctly. But, when I click on the “Run The Tests” button it fails. so why is that? or how come?

  **Your code so far**

// function largestOfFour(arr) {
//   let largestNumbers = [];
//   for (let i = 0; i < arr.length; i++) {
//     // console.log(Math.max(...arr[i]));
//     largestNumbers.push(Math.max(...arr[i]));
//   }
//   console.log(largestNumbers);
//   return arr;
// }

function largestOfFour(arr) {
return arr.map(function(group) {
  return group.reduce(function(prev, current) {
    return current > prev ? current : prev;
  });
});
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

check your return statement

1 Like

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