title: Javascript object sort and slice
body: <p>I'm trying to sort and then slice a set of javascript objects. I'm successfully slicing the data, but the sort is returning a list of categories that is neither alphabetically sorted by category nor by value.</p>
  
  <p>My CSV looks like this:</p>
  
  <pre><code>category,date_calc,value,YYYY,MM
  string1,2011-08-01,46440.16,2011,8
  string2,2013-03-01,68249.72,2013,3
  string1,2014-01-01,4285,2014,1
  string3,2012-03-01,47646.82,2012,3
  ...
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>d3.csv("data/ncc_category.csv", function(error, csv) {   
      var data = d3.nest()
      .key(function(d) { return d.category;})
      .rollup(function(d) { return d3.sum(d, function(g) {return g.value; }); }).entries(csv) 
  
      var sorted = data.sort(function (a, b) {
          return a.value - b.value; 
      }).reverse();
  
      var top10 = sorted.slice(0, 10); // slice
          console.log(top10);
  });
  </code></pre>
  
  <p>EDIT: 
  Screen grab for the first 4 objects in <code>data</code>. </p>
  
  <p><img src="https://i.stack.imgur.com/AddlE.png" alt="Console output for data:"></p>
  
  <p>Screen grab for the first 4 objects in <code>top10</code></p>
  
  <p><img src="https://i.stack.imgur.com/p2wC9.png" alt="Console output for top10"></p>