title: How might I return multiple arrays with equal values from a larger array with mixed values?
body: <p>I have an array that <em>after being sorted</em> appears like this:<br /></p>
  
  <pre><code>var arr = ["a", "a", "b", "b", "b", "b", "c", "c", "c"];
  </code></pre>
  
  <p><br />
  There are 2 <code>"a"</code> Strings, 4 <code>"b"</code> Strings, and 3 <code>"c"</code> Strings.
  <br /><br />
  I am trying to return 3 separate arrays, returning them one at a time from a loop, containing <strong>only</strong> matching values. So, upon the first iteration, the returned array would appear as <code>newArr = ["a", "a"]</code>,&nbsp;&nbsp;the second as <code>newArr = ["b", "b", "b", "b"]</code>&nbsp;&nbsp;and on the third iteration as <code>newArr = ["c", "c", "c"]</code>.&nbsp;&nbsp;
  <br /><br />
  However, this is a small array of predefined values, and I need an algorithm that can perform the same operation on an array of <em>unknown</em> size, <em>unknown</em> elements, and with an <em>unknown</em> number of like elements. (and keep in mind that the array is already sorted to begin with, in this context)
  <br /><br />
  Here's my crazy code that is displaying some unusual, and incorrect, results:<br /><br /></p>
  
  <pre><code>var arr = ["a", "a", "b", "b", "b", "b", "c", "c", "c"];
  
  for(var index = 0; index &lt; arr.length; index++)
  {
    var test = "";
    var newArr = []; // resets the new array upon each iteration
    var str = arr[index]; // initialized as the next unique index-value
  
    for(var i = index; i &lt; arr.length; i++)
    {
      if(arr[i] == str)
      {
        newArr.push(arr[k]);
        test += arr[i] + " ";
      }
      else
      {
        index = i; // changing the outer loop variable
        break; // exiting the inner loop
      }
    } // end of inner loop
  
    window.alert(test);
    setValues(newArr);
  
  } // end of outer loop
  
  function setValues(arrSorted)
  {
    var here = document.getElementById("here");
  
    for(var i = 0; i &lt; arrSorted.length; i++)
    {
      here.innerHTML += arrSorted[i] + "&amp;nbsp;";
    }
  
    here.innerHTML += "&lt;br /&gt;";
  
  } // end of setValues function
  </code></pre>