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.
This is the time span i want to look at
start = '2013-01-01';
end = '2013-01-08';
There is a list of assignments with start and end dates
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'}];
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:
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}];
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.
Are either of those ways on the right path or is there a smarter more efficient way?
Note: I'm doing this using javascript with underscore and moment js for dates.