Efficient way of calculating assignments per day with time span
<p>I have a problem I'm trying to solve, but i feel I'm not solving it in the most efficient way. Any new light on this is appreciated. </p>

<p>This is the time span i want to look at</p>

<pre><code>start = '2013-01-01';
end = '2013-01-08';
</code></pre>

<p>There is a list of assignments with start and end dates</p>

<pre><code>assignments = [{start: '2013-01-01', end: '2013-01-01'},
               {start: '2013-01-01', end: '2013-01-02'},
               {start: '2013-01-01', end: '2013-01-03'},
               {start: '2013-01-01', end: '2013-01-04'}];
</code></pre>

<p>I want to end up with a result, each date in the time span with a value that represents how many assignments were active that day. This is what i want the result to look like:</p>

<pre><code>result = [{date: '2013-01-01', value: 4},
          {date: '2013-01-02', value: 3},
          {date: '2013-01-03', value: 2},
          {date: '2013-01-04', value: 1},
          {date: '2013-01-05', value: 0},
          {date: '2013-01-06', value: 0},
          {date: '2013-01-07', value: 0},
          {date: '2013-01-08', value: 0}];
</code></pre>

<p>My attempts include iterating through each date in daterange and checking how many assignments fall on that day. I have also tried going the other way, iterating through assignments and then its start and end dates, pushing a value into an array for each date.</p>

<p>Are either of those ways on the right path or is there a smarter more efficient way?  </p>

<p>Note: I'm doing this using javascript with underscore and moment js for dates.</p>
