title: How to sum digits recursively javascript
body: <p>I'm learning the basics of JavaScript and am trying to write a recursive function to add together a group of integers.  For example, the function argument would be <code>1234</code> and the result should be <code>10</code>.  Here's what I have so far...</p>
  
  <pre><code>function sumDigits(numbersStr) {
  
    var numToString = numbersStr.toString()
    var numArr = numToString.split('').map(Number);
  
    var sum = 0;
  
    // base case
    if (numArr.length === 0) {
      return sum
    } 
  
    // recursive case
    else {
      var popped = numArr.pop();
      sum+=popped;
      return sumDigits(numArr);
  
    }
  }
  </code></pre>
  
  <p>But I get an infinite loop whenever I run this (my tab crashes).  If I'm popping the last element of an array, adding it to the <code>sum</code> variable, then calling the function again on the shortened array, then why do I get an infinite loop?  Many thanks!</p>