Basic Algorithm Scripting - Return Largest Numbers in Arrays

Hi,
Please assist with the below code. It’s meant to output the highest values in a multi-dimensional array. Output is as expected yet it fails on all 4 passing criteria.
Please advise where I might be going wrong?

Your code so far
function largestOfFour(arr) {
// You can do this!
var largest = 0;
var subset = ;

//console.log(Math.max(…arr[0]))
for (var i = 0; i < arr.length; i++) {

	  if (Math.max(...arr[i]) > largest) {
  		subset.push(Math.max(...arr[i]));
  	}
  	      	
}

return console.log(subset);
}

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

Link to the challenge:

Many thanks

You’re not returning anything except undefined. console.log logs to the console , it doesn’t actually do anything else

1 Like