Reputation: 3247
Suppose I have two arrays with numbers inside. I want to iterate through both arrays and pass each element to a method that accepts 2 parameters.
x = [2,3,9,1]
y = [1,9,2,1]
def add (x,y)
x+y
end
I want to be able to pass each element in x and y. I want to implement this in Ruby but Python or another language is fine.
Upvotes: 0
Views: 128
Reputation: 4759
This should also do the job:
# len(a) or len(b) can be used - As both are of same length
for i in range(len(a)):
add(a[i], b[i])
Upvotes: 1