title: Sum Numbers Between 1 and a Given Number Using Recursion - Javascript
body: <p>Summing numbers between one and a given number without recursion is simple:</p>
  
  <pre><code>function sumNums (num) {
    let array = [];
    for (let i = 0; i &lt;= num; i++) {
      array.push(i);
    }
    return array.reduce((a, b) =&gt; a + b);
  }
  console.log(sumNums(3)); 
  </code></pre>
  
  <blockquote>
    <p>6</p>
  </blockquote>
  
  <p>But what I don't understand, is that when we're using <strong>recursion</strong>, it causes the "loop" to occur throughout <em>the entire function</em>. </p>
  
  <p>So if we have a for-loop (or any loop) within a function that's using recursion, it will cause an error - right? </p>
  
  <p>And I assume that we'll need an array of the integers in order to reduce them - So know how else can we create an array of integers between one and and a given number without using some sort of loop?</p>
  
  <p><strong>EDIT</strong>: A simpler way of adding integers between 1 and num without recursion:</p>
  
  <pre><code>function sumNums (num) {
    let sum = 0;
    for (let i = 1; i &lt;= num; i++) {
      sum += i;
    }
    return sum;
  }
  console.log(sumNums(3)); 
  </code></pre>
  
  <p>No need to add the integers to an array and then reduce it. Just add them to an initializer variable instead.</p>