I have some data for a some graphs arranged in an array of arrays that looks like:
[[date1, value1], [date2, value2], [date3, value3]]
i.e. [["6-01-13", 5], ["6-03-13", 2], ["6-04-13", 11]]
My problem is that my graphing utility isn't graphing any data for "6-02-13", while I would like it to graph 0.
I have another array of all the valid dates, e.g. ["6-01-13", "6-02-13", "6-03-13", ...]
What's the best way to insert [date, 0]
into my data array for all dates that aren't already present in my data array?
I don't care about the array's ordering.
I figured I'd do something along the lines of:
dates_array.each do |date|
unless data_array.has_date(date)
data_array.push([date, 0])
end
end
But I can't think of how this has_date(date) method should work without looping through all the dates and checking that that date is represented in my data array (which would naively be a loop of loops and therefore not ideal).
edit: Existing data (and dates) are pulled from the database as arrays.