title: Infinite recursion in JavaScript quicksort?
body: <p>Here is the <a href="http://en.wikipedia.org/wiki/Quicksort">quicksort</a> code I wrote. The function doesn't work because it can't reach the base case. If I log the pivot, <code>r</code> and <code>l</code> to the console, they remain the same no matter how many times the sort function is called. So I wonder if the argument <code>l</code>, <code>r</code> are not really passed into the function as data. Why did it happen?</p>
  
  <pre><code>function sort(data){
      if(data.length &lt; 2){
          return data;
      }
      else{
          var l = [];
          var r = [];
          var pivot = parseInt(data.length/2);
          for(i=0; i&lt;data.length; i++){
              if(data[i] &gt; data[pivot]){
                  r.push(data[i]);
              }
              else{
                  l.push(data[i]);
              }
          }
          return sort(l).concat(sort(r));
      }
  }
  </code></pre>