1

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]]
2
  • Does x.zip(y) answer your needs? Commented Jul 16, 2012 at 6:57
  • Thanks guys. I remember there was a way to do it but I just can't remember. Commented Jul 16, 2012 at 8:03

2 Answers 2

6

The short answer is.....

x.zip y
Sign up to request clarification or add additional context in comments.

Comments

0
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"]] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.