title: The most elegant way to reuse aggregation related code in d3 rollup?
body: <p>I have multiple rollups that use identical code, ie:</p>
  
  <pre><code> rolledUpData1 = d3.nest()
                  .key(function (d) { return d.city; })
                  .rollup(function (values) {
                      return {
                          yearWeek: toYearWeek(values[0].date) + ' Mon',
                          mondayDate: parseYearWeek(toYearWeek(values[0].date) + ' Mon'),
                          totalRevenue: d3.sum(values, function (d) { return parseFloat(d.price) }),
                          }), //
                      }
                  })
                  .entries(filteredData)
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>rolledUpData2 = d3.nest()
                  .key(function (d) { return d.store; })
                  .rollup(function (values) {
                      return {
                          yearWeek: toYearWeek(values[0].date) + ' Mon',
                          mondayDate: parseYearWeek(toYearWeek(values[0].date) + ' Mon'),
                          totalRevenue: d3.sum(values, function (d) { return parseFloat(d.price) }),
                          }), //
                      }
                  })
                  .entries(filteredData)
  </code></pre>
  
  <p>What is the most elegant way of not repeating the code in each rollup? </p>
  
  <pre><code>                        yearWeek: toYearWeek(values[0].date) + ' Mon',
                          mondayDate: parseYearWeek(toYearWeek(values[0].date) + ' Mon'),
                          totalRevenue: d3.sum(values, function (d) { return parseFloat(d.price) }),
  </code></pre>