Largest Numbers in Array

I might be overlooking something but why does result have to be initialized as arr[i][0]. Why cant I just initialize it as 0?

Hi @lulz967 !

Welcome to the forum!

In the future, please do not post screenshots for code because it is hard to read. You can use the ask for help button which will post your code and link t the challenge.

As for this part arr[i][0], we are telling computer to assign the first number of each nested array to result and assume it is the largest number. If we find a number larger than the result than we will replace it and assign it to the result variable.

Also, if you feel comfortable with the spread operator, you can solve this challenge with just one for loop and Math.max.

Hope that makes sense.

1 Like

what happens if the biggest number is -3? would the function in that case be able to say that -3 is the biggest number, or would it say that it is 0?

1 Like

Thank you for your replies! It makes sense now.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.