title: Javascript quicksort algorithm implementation
body: <p>So I'm very new to javascript (came from c) and just started to learn the syntax, practicing with some exercises. I implemented a quicksort algorithm:</p>
  
  <pre><code>function sort(a)
  {
      var _sort = function(l, r)
      {
          if (l &gt;= r - 1)
              return;
          var p = r - 1;
          var y = l;
          var tmp;
          for (var i = l; i &lt; r - 1; i++)
              if (a[i] &lt; a[p])
              {
                  tmp = a[i];
                  a[i] = a[y];
                  a[y] = tmp;
                  y++;
              }
          tmp = a[y];
          a[y] = a[r - 1];
          a[r - 1] = tmp;
          _sort(l, y);
          _sort(y + 1, r);
      }
  
      _sort(0, a.length);
  }
  </code></pre>
  
  <p>It works fine for small arrays, however for arrays beyond 5000 elements I get stack size limit exceeded. I tried to increase it, but that didn't work. I suspect there's something wrong with the way I implemented the algorithm, can it be?</p>
  
  <p>My question is, how should I implement the algorithm, or bypass the stack size limitation (I think 5000 elements arrays are small), in order to make it work? I would be also glad with any style suggestions.</p>