title: Recursive SUM function javascript
body: <p>I have been given the function below in pseudocode and I am trying to translate it to JS, but I keep getting an infinity loop.</p>
  <hr />
  <h2>Update</h2>
  <p>Thanks zord, mid fixed the recursion issue. Now I get the wrong sum, any suggestions?</p>
  <p>What am I doing wrong?</p>
  <pre><code>function SUM(arr, left, right){
    
      if(left &gt; right){ 
          return 0 
      }
      else if(left == right){
        return arr[left]
      }
  
      mid = Math.floor((left + right) / 2);
  
      lsum = SUM(arr,left,mid);
      rsum = SUM(arr,mid+1,right); 
  
      return lsum + rsum
  
  }
  
  arr = [1,2,3,4,5]
  left = 0;
  right = arr.length - 1;
  
  
  console.log(SUM(arr, left, right));
  </code></pre>
  <p>Thanks!</p>