Why does the first pass put two numbers in the array? I was expecting to see one number each pass.
Also… the function is adding endNum into the array each time… yet the numbers are assigned to the array from the lowest number to the highest number passed into the function. Why is that the case?
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
but as the function gets called in order of the loop endNum is decreasing i.e. 20, 19, 18, 17 etc… Yet, the function is adding numbers into the array as 15, 16, 17 ,18 etc… If this is correct I do not understand how that is happening within the context of recursion, and if that is now how this recursive function works I do not understand what I am not seeing.
When you call a function, the code below it does not run until the function call finishes. Tme call with endNum-1 must finish and return before the push(endNum) happens.