title: Count unique elements in array without sorting
body: <p>In JavaScript the following will find the number of elements in the array. Assuming there to be a minimum of one element in the array</p>
  
  <pre><code>arr = ["jam", "beef", "cream", "jam"]
  arr.sort();
  var count = 1;
  var results = "";
  for (var i = 0; i &lt; arr.length; i++)
  {
      if (arr[i] == arr[i+1])
      {
        count +=1;
      }
      else
      {
          results += arr[i] + " --&gt; " + count + " times\n" ;
          count=1;
      }
  }
  </code></pre>
  
  <p>Is it possible to do this without using sort() or without mutating the array in any way? I would imagine that the array would have to be re-created and then sort could be done on the newly created array, but I want to know what's the best way without sorting.
  And yes, I'm an artist, not a programmer, your honour. </p>