Simplified a little

Continuing the discussion from freeCodeCamp Algorithm Challenge Guide: Return largest Numbers in Arrays:

I simplified it a little
function largestOfFour(arr) {
// You can do this!
var max=;
for (var i= 0; i<arr.length;i++)
{
max[i]=arr[i][0];

for(var j= 0; j<arr[i].length;j++){

   if(arr[i][j]>max[i]){
      max[i]=arr[i][j];
    }//if
  
  } //for
}//for

return max;

} //function

1 Like

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.

We have set your post to unlisted. Thanks for your understanding.

1 Like

Ok, I am sorry, I am new to the fcc community.

i know this is old one but i am just learning here, i tried this code and it did work.
i dont think i am that genius so here it is:

function largestOfFour(arr) {

  return arr.map(x =>{

    return Math.max(...x)

  });

}
5 Likes

//Used the inbuilt Math.max function with the spread operator for a simple solution
function largestOfFour(arr) {

var a=[ ]
for(let i=0;i<arr.length;i++)
{
var max=Math.max(…arr[i])
a.push(max)
}
return a
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

2 Likes