I just completed “Return Largest Numbers in Arrays”, and I don’t understand why var bigArray=0; has to be within the inner loop to work:
With the variable on the very outside, this function doesn’t work for the second array:
But with the variable within the inner loop, it works:
On this problem’s Wiki, it says the var must be within the inner loop “so it won’t be reassigned until we find a larger number.” But I’m not sure why it matters. Can anyone explain?
Thank you!