J
Jason Lillywhite
I suspect there is a cleaner way to do this with inject or collect.
a = [1,2,3]
b = [1,1,1]
c = []
i = 0
while i < 3 do
c << a - b
i += 1
end
p c
=> [0, 1, 2]
I tried a collect but can't figure out how to get variables from outside
the block to work inside the block. I was thinking something like
c = []
c.collect {|a,b| a - b}
but that is not it.
a = [1,2,3]
b = [1,1,1]
c = []
i = 0
while i < 3 do
c << a - b
i += 1
end
p c
=> [0, 1, 2]
I tried a collect but can't figure out how to get variables from outside
the block to work inside the block. I was thinking something like
c = []
c.collect {|a,b| a - b}
but that is not it.