title: How Does My Recursion Solution for Getting The Values Within A Range Truly work?
body: <p>I been working on this problem that asks to find the values within the two given inputs. For instance, input: (1,5) yields the result: [1,2,3,4,5]. This problem should give a solution that is done recursively. </p>
  
  <p>Here is the solution that works: </p>
  
  <pre><code>function rangeOfNumbers(startNum, endNum) {
    if (endNum - startNum === 0) {
      return [startNum];
    } else {
      var numbers = rangeOfNumbers(startNum, endNum - 1);
      numbers.push(endNum);
      console.log(numbers); 
      return numbers;
    }
  }
  </code></pre>
  
  <p>The trouble that I am having is understanding how this solution works. I tried debugging through console.log and it looks like values are added like this: </p>
  
  <pre><code>[ 1, 2 ]
  [ 1, 2, 3 ]
  [ 1, 2, 3, 4 ]
  [ 1, 2, 3, 4, 5 ]
  </code></pre>
  
  <p>If my endNum value is declared as 5 initially and I'm pushing endNum to the end of the array, why doesn't my array look like this: 
  [ 5, 4, 3, 2, 1 ]</p>
  
  <p>What's surprising was when I changed my recursive function to this: </p>
  
  <pre><code>var numbers = rangeOfNumbers(startNum+1, endNum);
  numbers.push(startNum);
  </code></pre>
  
  <p>The array looked like this: </p>
  
  <pre><code>[ 5, 4, 3, 2, 1 ]
  </code></pre>
  
  <p>Any feedback or clarification on this would be greatly appreciated, thanks!</p>