Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Old code
- i = 0
- @views.each do |view|
- while (view[1].to_s != (@startDate+i).to_s) && (i < 30) do
- #if no data for that day put 0 views in
- @monthViewArray.push(0)
- i+=1
- end
- #otherwise put in the number of views
- @monthViewArray.push(view[0])
- i+=1
- end
- # new, even more awesome code
- @monthViewArray = (30.days.ago.to_date..Date.today).map{ |date| # go through each of the last 30 days
- row = @views.find {|row| row[1].to_s==date.to_s} # find a row with this date (returns nil if there isn't one)
- row.nil? ? 0 : row[0] # if you found a row use it, otherwise use 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement