title: Range Recursion in JavaScript
body: <p>I was trying to solve a recursion problem that get the integers within a range (x, y).</p>
  
  <p>This takes both negative and positive numbers.</p>
  
  <p>An example of the expected results are:</p>
  
  <pre><code>range(2,9); // =&gt; [3,4,5,6,7,8]
  range(7,2); // =&gt; [6, 5, 4, 3]
  range(-9,-4)) // =&gt; [-8,-7,-6,-5]
  </code></pre>
  
  <p>Currently I have the ff:</p>
  
  <pre><code>var range = function(x, y) {
  
  var result = [];
  
  if(x &lt; y){
    for(var i = x+1; i &lt; y; i++){
    result.push(i);
  }
  
  return result;
  }
  
  if(x &gt; y){
    for(var j = x-1; j &gt; y; j--){
    result.push(j);
  }
  return result;
  
  }
  
  };
  </code></pre>
  
  <p>How can I convert my for loops into recursion with the given rules.</p>