How below?
Note. The size should be equal as for the array.
a = [1, 5, 9] b = [3, 2, 11] p a.size.times.map{|i| [a[i],b[i]].max}
or
a = [1, 5, 9] b = [3, 2,11] p a.size.times.map{|i| a[i]>b[i] ? a[i] : b[i] }
Or
a = [1, 5, 9] b = [3, 2, 11] p a.each_index.map{|i| a[i]>b[i] ? a[i] : b[i] }
Benchmark
require 'benchmark' iterations = 10_000 a = [1, 5, 9] b = [3, 2,11] def stefan(a,b) [a, b].transpose.map(&:max) end def abe(a,b) a.zip(b).map(&:max) end def babai1(a,b) a.size.times.map{|i| a[i]>b[i] ? a[i] : b[i] } end def babai2(a,b) a.size.times.map{|i| [a[i],b[i]].max} end def babai3(a,b) a.each_index.map{|i| a[i]>b[i] ? a[i] : b[i] } end Benchmark.bm do |bm| bm.report('Stefan') do iterations.times do stefan(a,b) end end bm.report('Abe') do iterations.times do abe(a,b) end end bm.report('babai1') do iterations.times do babai1(a,b) end end bm.report('babai2') do iterations.times do babai2(a,b) end end bm.report('babai3') do iterations.times do babai3(a,b) end end end
output
user system total real Stefan 0.047000 0.000000 0.047000 ( 0.046874) Abe 0.047000 0.000000 0.047000 ( 0.046873) babai1 0.031000 0.000000 0.031000 ( 0.031249) babai2 0.062000 0.000000 0.062000 ( 0.062497) babai3 0.032000 0.000000 0.032000 ( 0.031249)