Robert Klemme
9/10/2008 4:59:00 PM
On 10.09.2008 17:55, ara.t.howard wrote:
> c = a.zip(b).map{|pair| pair.first + pair.last}
> c = Array.new(a.size){|i| a[i] + b[i]}
> the second is far more efficient for large arrays - in terms of memory.
Well, if you want to avoid the temp Array you can do
irb(main):001:0> a = 0,1,2
=> [0, 1, 2]
irb(main):002:0> b = 3,4,5
=> [3, 4, 5]
irb(main):003:0> a.to_enum(:zip, b).map {|x,y| x + y}
=> [3, 5, 7]
Cheers
robert