How do I add values in an array when there is a null entry?
Posted
by
Angela
on Stack Overflow
See other posts from Stack Overflow
or by Angela
Published on 2010-12-27T06:45:03Z
Indexed on
2010/12/27
6:53 UTC
Read the original article
Hit count: 202
I want to create a real time-series array. Currently, I am using the statistics gem to pull out values for each 'day':
define_statistic :sent_count, :count
=> :all, :group => 'DATE(date_sent)',
:filter_on => {:email_id => 'email_id
> = ?'}, :order => 'DATE(date_sent) ASC'
What this does is create an array where there are values for a date, for example
[["12-20-2010",1], ["12-24-2010",3]]
But I need it to fill in the null values, so it looks more like:
[["12-20-2010",1], ["12-21-2010",0], ["12-22-2010",0], ["12-23-2010",0], ["12-24-2010",3]]
Notice how the second example has "0" values for the days that were missing from the first array.
© Stack Overflow or respective owner