# Returning largest number within sub arrays

Tell us what’s happening:

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?

``````
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]]));

``````

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`.

Challenge: Return Largest Numbers in Arrays

Two problems:

1. You should reset your bignumber for each subarray

2. What if the arr entries are all negative

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?

Why would it reset the number? You have no code reseting the value on each iteration.

Just removing the `= 0` won’t be enoughto ix this becauseyou need some code to reset the bignumber on each loop iteration.

Unrelated - what is this doing for you? I don’t think that you need this.

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

You are getting closer.

I’m not sure that, you mean to be setting arr[i] to a value here?

Also, I would only decide that you have checked that you have the biggest after you have fully checked each subarray.

What will happen if you use
`[1, 2, 3, 4], [5, 6, 7, 8], [-1, -2, -3, -4], [-5, -6, -7, -8]]`?

You should have `[4, 8, -1, -5]` as your result.

It can be very useful to write out what will happen in every loop iteration.