I am so close to getting this thing down, but when it comes to negative numbers (passing the last test), I am so dead. If I set the array numbers to negative numbers just to pass the test, then I know I’m cheating. If I empty the array and push the array values in, the final result is always an empty array (totalArr[i].push(arr[i][j]);).

Please helpfully help.

Thanks.

Your code so far

function largestOfFour(arr) {
// You can do this!
var totalArr = [0,0,0,0];
for(var i = 0; i < arr.length; i++){
for(var j = 0; j < arr[i].length; j++){
if(arr[i][j] > totalArr[i]){
totalArr[i]=arr[i][j];
}
}
}
return totalArr;
}
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_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

Let’s say I tell you I have 4 pieces of paper in my pocket with a number (negative or positive) written on each. If I hand them to you one at a time, how would you figure out which one is the smallest?

Focus on the algorithm steps here and do not worry about the code just yet.

To find them smallest value of the pieces, I’d compare each one to the other(s) as they are handed out to me.

I’ve been reading your explanation over and over for like five minutes, but I’m still totally stuck and am wondering how this relates to the algorithm.

I look at them both and pick the one with the smaller numeric value as the smallest one.

The third piece of paper is given to me.

I look at that one. If its value is greater than that of the previously selected one, then the previous smallest keeps its title of the smallest. If not, then the newest piece of paper is selected as the smallest one.

Finally, the last piece of paper is handed to me. I will compare it with the smallest value I have now. If the piece of paper most recently handed to me has a lesser value than that of the last one, IT will be selected as the smallest one and the algorithm ends. If the paper most recently handed to me has a value greater than that of the last one, then the previous one keeps its title of the lesser of all the others. The algorithm ends.

Exactly, so how can you incorporate that in steps 1-2 above? Once you figure that out, you can write the code to solve the challenge. You have the basic gist of the code already.

You told me to find the smallest value of each piece of paper. If you meant to find the largest, then I would go over the same algorithm again and instead of finding the one with the smallest value, try to find the largest.

Let me apologize about something that might have confused you a bit. In my hypothetical example, I should have asked how you would know when you found the largest number.

Since I messed my example up, I will explain how I would figure out which piece of paper has the largest number.

I assume the first piece of paper has the largest number and I remember that number as the “largest”.

I am handed the 2nd piece of paper and if it contains a larger number than the one I have assigned to my memory, then I remember the new number as the “largest”.

I am handed the 3rd piece of paper and if it contains a larger number than the one I have assigned to my memory, then I remember the new number as the “largest”.

I am handed the 4th piece of paper and if it contains a larger number than the one I have assigned to my memory, then I remember the new number as the “largest”.

Now that all the pieces of paper have been reviewed, I just have to remember the number I have stored in my memory as the “largest”.

This is the kind of process you should go through for all of the challenges. No code written. I just think through the steps of how to do it manually. In the case of above, “my memory” will just be a variable I created to store the largest number found so far.

brother @ConnerOw1115 I solved that same problem by using the Math.max/min methods, I won’t tell you the answer but a little hint: to pass an array to one of these methods do