2 dimensional array to single arrays

Hi,

I have a nasty loop which creates 2 single arrays from a 2 dimensional
array,

is there a quicker way to do it?

[["a",1],["b",2],["c",3]]

So i want an array
["a","b","c"]

and

[1,2,3]

Any quick method to do this?

JB

···

--
Posted via http://www.ruby-forum.com/.

letters, numbers = ["a",1],["b",2],["c",3]].transpose

Farrel

···

2008/11/21 John Butler <johnnybutler7@gmail.com>:

Any quick method to do this?

--
Aimred - Ruby Development and Consulting

John Butler wrote:

Hi,

I have a nasty loop which creates 2 single arrays from a 2 dimensional
array,

is there a quicker way to do it?

[["a",1],["b",2],["c",3]]

So i want an array
["a","b","c"]

and

[1,2,3]

Any quick method to do this?

JB

my_array = [["a",1],["b",2],["c",3]]

letters = my_array.collect {|array| array[0]}
numbers = my_array.collect {|array| array[1]}

···

--
Posted via http://www.ruby-forum.com/\.