Tell us what’s happening:
it successful with me using the map …look at the end of code /Done using map/
but I’m trying to solve it using filter …it didn’t work!.
why?
Your code so far
function largestOfFour(arr) {
let y = [];let z=0;
for(let i = 0 ; i < arr.length ; i++)
{
Math.max(arr[i].filter(num => {
if(num>z){z=num}
}))
}
return z;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
/* let x = [];
for(let i = 0 ; i < arr.length ; i++)//
{
x.push(Math.max(...arr[i].map(num => num)));
}
return x;*/
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36
.
Challenge: Return Largest Numbers in Arrays
Link to the challenge: