title: Counting duplicate objects in array of Javascript objects
body: <p>I'm trying to parse the sub-objects of a Javascript object to count the number of sub-objects that are the same and return a new JSON object with those counts. That's probably not very clear, so here's the <a href="http://jsfiddle.net/eLTFC/" rel="nofollow">fiddle</a>.</p>
  
  <p>Given the <code>crsListData</code> in the fiddle, I'd like to return this:</p>
  
  <pre><code>objToReturn = [
              {
                  key: "Consigned",
                  values:
                      [
                          { mapKey: 2007 (4), mapVal: [["Ford F-150 (3)"], ["Honda Civic (1)"]] },
                          { mapKey: 2011 (1), mapVal: "Toyota Camry (1)" },
                          { mapKey: 2005 (1), mapVal: "Dodge RAM (1)" }
                      ]
              },
              {
                  key: "Run",
                  values:
                      [
                          { mapKey: 2007 (2), mapVal: "Ford F-150 (2)" },
                          { mapKey: 2011 (1), mapVal: "Toyota Camry (1)" }
                      ]
              },
              {
                  key: "Sold",
                  values:
                      [
                          { mapKey: 2007 (1), mapVal: "Ford F-150 (1)" },
                          { mapKey: 2011 (1), mapVal: "Toyota Camry (1)" }
                      ]
              }
          ];
  </code></pre>
  
  <p>If you'll notice in the fiddle, I've commented on a part about the mapKey and mapValue. They will be determined by function parameters obtained from a select option to order by Model (count)/Year (count), or Year (count)/Model (count).</p>
  
  <p>My end goal here is to generate an HTML tree that essentially looks like this:</p>
  
  <ol>
  <li><p>Consigned (# of consigned)</p>
  
  <ul>
  <li>2007 (total count of 2007 models)
  <ul>
  <li>Model 1 (count)</li>
  <li>Model 2 (count)</li>
  </ul></li>
  <li>2011 (total count of 2007 models)</li>
  </ul></li>
  <li><p>Run (# of run)</p>
  
  <ul>
  <li>2007 (total count of 2007 models)
  <ul>
  <li>Model 1 (count)</li>
  <li>Model 2 (count)</li>
  </ul></li>
  <li>2011 (total count of 2007 models)</li>
  </ul></li>
  <li>Sold (same as above)</li>
  </ol>
  
  <p>The order of the years should be based on the total count of models for that year (highest # first). Similarly, the order of the models under the years should be ordered by highest count.</p>
  
  <p>Alternatively, if the user selects Model/Year for the grouping, I'd like to generate:</p>
  
  <ol>
  <li><p>Consigned (# of consigned)</p>
  
  <ul>
  <li>Model1 (total count of this model for all years)
  <ul>
  <li>Year 1 (count of models for this year)</li>
  <li>Year 2 (count of models for this year)</li>
  </ul></li>
  <li>Model2 (total count of this model for all years)</li>
  </ul></li>
  <li><p>Run (# of run)</p>
  
  <ul>
  <li>Model1 (total count of this model for all years)
  <ul>
  <li>Year 1 (count of models for this year)</li>
  <li>Year 2 (count of models for this year)</li>
  </ul></li>
  <li>Model2 (total count of this model for all years)</li>
  </ul></li>
  <li>Sold (same as above)</li>
  </ol>
  
  <p>The ordering of this would be based on counts as well. Let me know if you need any clarification! Thanks!</p>