Hello!
The simplest answer is because the count function starts filling the array when the if (n === 1)
is executed, not before . In other words, the first value of numbers
is [1]
, then the n is just pushed to the array.
Look at the following topics:
- The answer I gave to @dareedyone.
- Use Python’s tutor script visualizer and paste Your function there, then click on Visualize Execution.
If You still don’t understand I’ll try to explain it more.