From: Jack Bauer Date: 2009-04-30T23:23:28+09:00 Subject: Re: Advanced array merging 7stud -- wrote: > > Those two requirements are often at odds with each other. For instance, > "inject" and "fastest" should not be used in the same sentence. > > result = [] > > arr.each do |sub_arr| > counter_total = 0 > > sub_arr.each do |obj| > counter_total += obj.counter > end > > sub_arr[0].counter = counter_total > result << sub_arr[0] #or result << [sub_arr[0]] > end Thanks, 7stud. I forgot to mention in my description that after it did the sum of the first item in each of the 3 subarrays to move on and do all the second items, then the third, etc. Using yours as a base I ended up with: index = 0 array[0].length.times do counter_total = 0 array.each do |sub_array| counter_total += sub_array[index].counter end array[0][index].counter = counter_total data_stream_out << array[0][index] index += 1 end Works like a charm and enormously faster than what I was doing before I posted this thread. Before I asked for help here I was using inject and the calculation was taking 28 seconds to complete. This one took 4 and there were about 2,000 more records this time too. -- Posted via http://www.ruby-forum.com/.