title: How to create a histogram from a flat Array in Ruby
body: <p>How do I create a histogram of an array of integers? For example:</p>
  
  <pre><code>data = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10]
  </code></pre>
  
  <p>I want to create a histogram based on how many entries there are for <code>0</code>, <code>1</code>, <code>2</code>, and so on. Is there an easy way to do it in Ruby?</p>
  
  <p>The output should be two arrays. The first array should contain the groups (bins), the second array should contain the number of occurrences (frequencies).</p>
  
  <p>For <code>data</code> given above, I would expect the following output:</p>
  
  <pre><code>bins         # =&gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  frequencies  # =&gt; [1, 1, 5, 6, 4, 2, 3, 5, 1, 2, 1]
  </code></pre>