title: Underscore.js groupBy multiple values
body: <p>Using Underscore.js, I'm trying to group a list of items multiple times, ie</p>
  
  <p>Group by SIZE then for each SIZE, group by CATEGORY...</p>
  
  <p><a href="http://jsfiddle.net/rickysullivan/WTtXP/1/">http://jsfiddle.net/rickysullivan/WTtXP/1/</a></p>
  
  <p>Ideally, I'd like to have a function or extend <a href="http://underscorejs.org/#groupBy"><code>_.groupBy()</code></a> so that you can throw an array at it with the paramaters to group by.</p>
  
  <pre class="lang-js prettyprint-override"><code>var multiGroup = ['size', 'category'];
  </code></pre>
  
  <p>Probably could just make a mixin...</p>
  
  <pre class="lang-js prettyprint-override"><code>_.mixin({
      groupByMulti: function(obj, val, arr) {
          var result = {};
          var iterator = typeof val == 'function' ? val : function(obj) {
                  return obj[val];
              };
          _.each(arr, function(arrvalue, arrIndex) {
              _.each(obj, function(value, objIndex) {
                  var key = iterator(value, objIndex);
                  var arrresults = obj[objIndex][arrvalue];
                  if (_.has(value, arrvalue))
                      (result[arrIndex] || (result[arrIndex] = [])).push(value);
  </code></pre>
  
  <p>My head hurts, but I think some more pushing needs to go here...</p>
  
  <pre class="lang-js prettyprint-override"><code>            });
          })
          return result;
      }
  });
  
  properties = _.groupByMulti(properties, function(item) {
  
      var testVal = item["size"];
  
      if (parseFloat(testVal)) {
          testVal = parseFloat(item["size"])
      }
  
      return testVal
  
  }, multiGroup);
  </code></pre>