title: Rails: Creating an array with an incrementing attribute?
body: <p>this is my first question on Stackoverflow, so don't tear me apart! I apologize if my question is too long or basic, but I think it would be easier for all involved to understand my problem if I type plainly, clearly, and plentifully. If my question formatting can be improved, please let me know for later questions.</p>
  
  <p>To put things in context, I am creating a Ruby on Rails app that involves displaying an array of records(<strong>Times</strong>) on Googlegraphs. There are two important attributes of these <strong>Times</strong> records; their <strong>'date'</strong> attribute and <strong>'hours_worked'</strong> attribute. Simply put, I need to display all of the <strong>'hours_worked'</strong> on a specific dates on the graph. So the first element of the array to be displayed on the graph holds all of the <strong>'hours_worked'</strong> values for the first date, the second element holds all of the <strong>'hours_worked'</strong> values for the second date, and so on.</p>
  
  <p>Obviously I can't just put all of the records <strong>'hours_worked'</strong> values into an array, because then the <strong>'date'</strong> attribute would be completely ignored. If I had an array of <strong>'hours_worked'</strong> where two elements were on the same <strong>'date'</strong>, the graph wouldn't know this and would simply display them all without acknowledging the <strong>'date'</strong> at all.</p>
  
  <p>My "Solution" with pseudo-code:</p>
  
  <p>I though that I could try to iterate through all of <strong>'Time'</strong> records and split them into records whose <strong>'dates'</strong> already existed in one array, and put all of the copies in another array:</p>
  
  <pre><code>@array1 = []#Original values
  @array2 = []
  
  @task.time_and_attendances.each do |f|
   if f.date is not in @array2
   @array2 &lt;&lt; f
  
  else
  
    @array1 &lt;&lt; f
  </code></pre>
  
  <p>Then I wanted to compare the two arrays and, if @array2 contained any dates that @array1 contained, simply add the <strong>'hours_worked'</strong> together. Because @array1 would contain all of the records that required this addition, dates that have several records would just have their <strong>'hours_worked'</strong> attribute combined. This would give me an array where each value is the total amount of <strong>'hours_worked'</strong> for every single date.</p>
  
  <p>That would be the ideal solution to my problem, but I am stumped about how to implement it. Does anyone out there have any ideas?</p>