I have a problem that I am trying to solve, but I feel that I am not solving it in the most efficient way. Any new light on this is appreciated.
This is the period of time that I want to look at
start = '2013-01-01'; end = '2013-01-08';
List of appointments 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 get a result every day in a time span with a value representing how many appointments were active that day. This is what I want the result to look like this:
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 a daterange and checking how many jobs fall out on that day. I also tried to go the other way, iterating through the destination, and then its start and end dates by pushing a value into an array for each date.
Is there one of these ways on the right track, or is there a smarter, more efficient way?
Note. I do this using javascript with underscore and js moment for dates.