I feel like I’m coming pretty close! But I still can’t ifugre out how to return four of the largest numbers within the sub arrays. Can someone please help and give me a hint as to where I’m going wrong?
Your code so far
function largestOfFour(arr) {
var largarr = []
var bignumber = 0
if ( typeof(arr) == "object"){
for (var i = 0; i < arr.length; i++) {
if (arr[i][i] > bignumber) {
arr[i][i] = bignumber;
largarr.push(bignumber);
}}
return largarr
}
;
}
console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.
I just took out “= 0” fo bignumber which I think should solve the second issue. Isn’t the loop supposed to reset the bignumber for me as it goes through each sub array?
Ah, you are only looping over the outer array, not the inner array at all. Where are you finding the biggest number of each subarray? You are only checking arr[i][i]
function largestOfFour(arr) {
var largarr = []
var bignumber = 0
for (var i = 0; i < arr.length; i++) {
for (var x = 0; x < arr.length[i]; x++) {
if (arr[i][x] > bignumber){
arr[i][x] = bignumber;
largarr.push(bignumber);
}
return largarr
}
}
;
}
I think I’ve got it looping through the sub arrays know, just not sure how to reset the variable after each iteration and haven’t been able to find anything on google. Really doing my best to not look at the solution right now