Hi!
I want to do something like that:
a = Array.new(1000000, 1)
b = Array.new(1000000, 2)
c = Array.new(1000000)
for i in 0 ... a.length
c[i] = a[i] + b[i]
end
This looks a bit too C-ish for me.
Should i use
(0 ... a.length).each {|i| c[i] = a[i] + b[i]}
or
a.length.times {|i| c[i] = a[i] + b[i]}
or
a.each_index {|i| c[i] = a[i] + b[i]}
Which is the 'ruby way' of doing that?
Background: I did some timing and found
a.collect! {|x| x+1}
to be twice as fast as
for i in 0 ... a.length
a[i] += 1
end
--
The early bird catches the worm. If you want something else for
breakfast, get up later.