Here is my current code:
var largestNumbers = new Array(4);
function largestOfFour(arr) {
var biggest = Math.max.apply(null, largestOfFour)
for (var index in arr) {
for(var i=0; i < arr[index].length; i++){
if (arr[index] > biggest){
arr[index].push(largestNumbers);
}
else if (arr[index] < biggest) {
arr[index].splice(0, 1);
}
}
}
return largestNumbers;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
My objective is to find the largest number in each of the subarrays and then put those values into another array and then return that value. I have been searching around for things like "How to extract a subarray from array" and that has led to me using the splice function. I'm not sure if I'm using it right, but I'm trying everything I've got because I've been stuck on this problem for 2 days now. If anyone could just lead me in the path to solve this problem, I would be more than grateful. Thank you all so much.
Furthermore, I was using this site to try and guide me along. There is a snippet of code that attempts to resolve a problem similar to mine in the latter half of the page. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply