title: Group array by index
body: <p>I have an array, that looks like this:</p>
  
  <pre><code>colors = [
      [356, 11, 30, 1],
      [354, 10, 1, 1],
      [220, 15, 33, 14],
      [51, 4, 69, 31],
      [38, 4, 54, 32],
      [33, 53, 52, 33],
      [19, 28, 78, 34],
      [0, 0, 27, 36]
  ];
  </code></pre>
  
  <p>It is an array of HSL colors with <code>colors[0]</code>, <code>colors[1]</code>, <code>colors[2]</code> representing HSL values and <code>colors[3]</code> representing the group that this color belongs to. I have 36 groups of colors.</p>
  
  <p>I want to be able to get the frequency of colors in each group (so count of <code>color[3]</code>) and also sum the <code>colors[1]</code> of each group.</p>
  
  <p>Could you help me setup my code? I’ve tried making an object with keys for every group to make this easier to work with, but couldn’t ...</p>
  
  <p>Here's the code I was trying to transform my array and make it easier to make the sum and frequency calculations:</p>
  
  <pre><code>     hueGroups = {};
       for (var i = 0;i&lt;colors.length-1;i++) {
       var group = colors[i][3];
       hueGroups[group] = colors[i];
       }
  
      And it gives me:
      { '1': [ 354, 10, 1, 1 ],
        '14': [ 220, 15, 33, 14 ],
        '31': [ 51, 4, 69, 31 ],
        '32': [ 38, 4, 54, 32 ],
        '33': [ 33, 53, 52, 33 ],
        '34': [ 19, 28, 78, 34 ] }
  </code></pre>
  
  <p>I also would prefer not using external libraries, I’ve seen solutions using Underscore.js.</p>