title: RangeError: Maximum call stack size exceeded using Array.forEach
body: <p><strong>src/QuickSort.js</strong></p>
  
  <pre><code>var quick_sort = function(unsorted) {
    if (unsorted.size &lt;= 1)
      return unsorted;
  
    var pivot = unsorted.pop();
    var less = new Array();
    var greater = new Array();
  
    unsorted.forEach(function(element){
      if (element &gt; pivot)
        less.push(element);
      else
        greater.push(element);
    });
  
    return quick_sort(less) + [pivot] + quick_sort(greater);
  };
  </code></pre>
  
  <p><strong>spec/QuickSort.js</strong></p>
  
  <pre><code>describe("#quick_sort", function() {
  
    it("should sort the unsorted array", function() {
      var unsorted = [8, 2, 10, 5, 4, 9, 7, 1, 6, 3];
      var sorted = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
      expect(quick_sort(unsorted)).toEqual(sorted);
    });
  
  });
  </code></pre>
  
  <p><strong>Error message</strong></p>
  
  <pre><code>RangeError: Maximum call stack size exceeded
      at Array.forEach (native)
      at quick_sort (file://localhost/Users/jasonkim/projects/algorithm-everyday/quick_sort/javascript/src/QuickSort.js:9:12)
      at quick_sort (file://localhost/Users/jasonkim/projects/algorithm-everyday/quick_sort/javascript/src/QuickSort.js:16:10)
  </code></pre>
  
  <p>I am trying to test quick sort function using jasminejs. I am getting the error above. I have the terminating condition above <code>if (unsorted.size &lt;= 1) { return unsorted }</code>. I am not sure why it's not terminating and goes into infinite loop.</p>