From: 7stud -- Date: 2009-05-01T06:31:16+09:00 Subject: Re: Advanced array merging Jack Bauer wrote: > 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 > Whoops. That's not what my code does--it sums the totals within one array. I did a vertical traversal rather than a horizontal traversal. > 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. I read your original post again and with all the talk of merging and summing, I decided I have no idea what you are trying to do. If you've got what you want--great! -- Posted via http://www.ruby-forum.com/.