I am trying to find the maximum number within each of four subarrays, push each max to a new array that includes all four maxes and return that array. When I run this code it returns an array with four values, but they are all null. What am I doing wrong?
largest = [];
function largestOfFour(arr) {
for (i = 0; arr.length > i; i++) {
var tempSub = arr.slice(i , i + 1);
largest.push(Math.max.apply(Math, tempSub));
}
return largest;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]], "");
[ 5, 27, 39, 1001 ]?largestOfFour()?largestOfFour(arr)only lists one parameter in its signature.