title: dividing and aggregating json data
body: <p>I have some JSON data I need to divide then aggregate. Here is a sample of its format.</p>
  
  <pre><code>data2 = [{"startDate": 1396263600.0, "adId": 2483231759355, "endDate": 1401101940.0,        "impressions": 754831},
  {"startDate": 1393851600.0, "adId": 2750329551133, "endDate": 1404212340.0, "impressions":    3947368},
  {"startDate": 1401620400.0, "adId": 1311595275159, "endDate": 1404212340.0, "impressions": 630000}];
  </code></pre>
  
  <p>I want to uniformly divide up the impressions for each day in the date range. (ie if there are 100 impressions in a range of 10 days then each day will get 10 impressions). Then I want to aggregate the number of impressions on all the adIds for each day (ie if there are 2 ads on one day, then they get combined). So the final result will be a array of days and impressions. Not too familiar with javascript so not sure if there are any functions to make my life easier here. Any suggestions?</p>
  
  <p>I plan on using this function to count number of days between dates:</p>
  
  <pre><code>function days_between(date1, date2) {
  
      // The number of milliseconds in one day
      var ONE_DAY = 1000 * 60 * 60 * 24;
  
      // Convert both dates to milliseconds
      var date1_ms = date1 * 1000;
      var date2_ms = date2 * 1000;
  
      // Calculate the difference in milliseconds
      var difference_ms = Math.abs(date1_ms - date2_ms);
  
      // Convert back to days and return
      return Math.round(difference_ms/ONE_DAY);
  
  }
  </code></pre>