Reputation: 2405
I have 2 arrays. For example
x= [1,2,3,4,5]
y= [a,b,c,d,e]
How do I merge them so that I have an array like below
z=[[1,a],[2,b],[3,c],[4,d],[5,e]]
Upvotes: 1
Views: 102
Reputation: 3739
1.9.3p194 :011 > x= [1,2,3,4,5]
=> [1, 2, 3, 4, 5]
1.9.3p194 :012 > y= ['a','b','c','d','e']
=> ["a", "b", "c", "d", "e"]
1.9.3p194 :013 > x.zip(y)
=> [[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, "e"]]
Upvotes: 0