title: Counting the occurrences / frequency of array elements
body: <p>In Javascript, I'm trying to take an initial array of number values and count the elements inside it. Ideally, the result would be two new arrays, the first specifying each unique element, and the second containing the number of times each element occurs. However, I'm open to suggestions on the format of the output.</p>
  
  <p>For example, if the initial array was:</p>
  
  <pre><code>5, 5, 5, 2, 2, 2, 2, 2, 9, 4
  </code></pre>
  
  <p>Then two new arrays would be created. The first would contain the name of each unique element:</p>
  
  <pre><code>5, 2, 9, 4
  </code></pre>
  
  <p>The second would contain the number of times that element occurred in the initial array:</p>
  
  <pre><code>3, 5, 1, 1
  </code></pre>
  
  <p>Because the number 5 occurs three times in the initial array, the number 2 occurs five times and 9 and 4 both appear once.</p>
  
  <p>I've searched a lot for a solution, but nothing seems to work, and everything I've tried myself has wound up being ridiculously complex. Any help would be appreciated!</p>
  
  <p>Thanks :)</p>