title: D3.nest() isn't giving me the data structure I need
body: <p>I'm using D3 and having trouble getting my data nested the way I need. I'll try to simplify the scenario to its essence for this question. </p>
  
  <p>I have expense data saved to variable <code>expenses</code>. Each object in the array represents a single purchase on a particular date at a particular brick-and-mortar store. ("StoreID" is unique; for brevity I'm omitting street address):</p>
  
  <pre><code>// original data
  
  var expenses =
  
     [
       {"storeID":"4872379","storeName":"Gap","zipCode":"10032","amount":34.88,"date":"11/12/2015"},
       {"storeID":"4872379","storeName":"Gap","zipCode":"10032","amount":-34.88,"date":"11/15/2015"},
       {"storeID":"2209875","storeName":"Banana Republic","zipCode":"10003","amount":1650.54,"date":"12/01/2015"},
       {"storeID":"5434432","storeName":"Gap","zipCode":"10031","amount":120.11,"date":"11/18/2015"},
       {"storeID":"5434432","storeName":"Gap","zipCode":"10031","amount":45.5,"date":"12/01/2015"},
       {"storeID":"5434432","storeName":"Gap","zipCode":"10031","amount":117.08,"date":"12/01/2015"}
     ]
  </code></pre>
  
  <p>What I want to do is group <code>amount</code>/<code>date</code> pairs as objects in a single array for each unique store. This is what I'd like to end up with: </p>
  
  <pre><code>// desired structure
  
    [
      {"key":"2209875",
       "storeName":"BananaRepublic",
       "zipCode":"10003",
       "values": [
         {"amount":1650.54,
          "date":"12/01/2015"}]
      },
      {"key":"4872379",
       "storeName":"Gap",
       "zipCode":"10032",
       "values": [
          {"amount":34.88,
           "date":"11/12/2015"},
          {"amount":-34.88,
           "date":"11/15/2015"}]
      }, 
      {"key":"5434432",
       "storeName":"Gap",
       "zipCode":"10031",
       "values": [
         {"amount":120.11,
          "date":"11/18/2015"},
         {"amount":45.5,
          "date":"12/01/2015"},
         {"amount":117.08,
          "date":"12/01/2015"}]
      }
    ]
  </code></pre>
  
  <p>Using d3.nest(), I'm only able to get this far:</p>
  
  <pre><code> // getting closer
  
   var expensesByStoreID = d3.nest()
     .key(function(d) { return d.storeID; })
     .entries(expenses);
  
   // expensesByStoreID holds this:
  
  [
    {"key":"2209875",
     "values": [
        {"storeID":"2209875",
         "storeName":"BananaRepublic",
         "zipCode":"10003",
         "amount":1650.54,
         "date":"12/01/2015"}]
    },
    {"key":"4872379",
     "values": [
        {"storeID":"4872379",
         "storeName":"Gap",
         "zipCode":"10032",
         "amount":34.88,
         "date":"11/12/2015"},
        {"storeID":"4872379",
         "storeName":"Gap",
         "zipCode":"10032",
         "amount":-34.88,
         "date":"11/15/2015"}]
     }, 
     {"key":"5434432",
      "values": [
         {"storeID":"5434432",
          "storeName":"Gap",
          "zipCode":"10031",
          "amount":120.11,
          "date":"11/18/2015"},
         {"storeID":"5434432",
          "storeName":"Gap",
          "zipCode":"10031",
          "amount":45.5,
          "date":"12/01/2015"},
         {"storeID":"5434432",
          "storeName":"Gap",
          "zipCode":"10031",
          "amount":117.08,
          "date":"12/01/2015"}]
      }
  ]
  </code></pre>
  
  <p>Each <code>amount</code> and <code>date</code> are together in an object but the store details are also there, <i>repeatedly</i>. I want the store details stored just once per store object. It becomes an efficiency problem because the database contains many thousands of stores and purchases. </p>
  
  <p>Is there something I can change in my d3.nest() code? Is there a plain Javascript function that would be able to turn my data structure from "original" to "desired"? Any help would be appreciated. :-)</p>