Return largest number in a array

Return largest number in a array
0

#1

function findLar(sArr){
var big = 0;
for( var i = 0; i < sArr.length; i++ ){
if( sArr[i] > big){
sArr = big;
}
}
}

function largestOfFour(arr) {

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

bigArr.push(findLar(arr[j]));

}

// You can do this!
return bigArr;
}

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

This should work but it keeps on returning null how do i get it to return the correct values


#2

Use arr.sort()
Use a for loop to sort through all inner arrays from largest to smallest and take the first element in each array and put them into a new one.


#3

Start your debugging with console.log().

function largestOfFour( arr ) {
  var bigArr = [];
  for(var j = 0; j < arr.length; j++){
    console.log( findLar(arr[j]) ); // <-- is this the value you were expecting 
    bigArr.push(findLar(arr[j]));
  }