Convert multi dimentional array to array of hashes

Hi,

How can I turn and array like this this

[[1,2,3,4,5],[1,2,3,4,5]]

into this

[{:lt=>1,:ln=>1},{:lt=>2,:ln=>2},{:lt=>3,:ln=>3},{:lt=>4,:ln=>4},{:lt=>5,:ln=>5}]

Cheers

You can try something like that :

a = [[1,2,3,4,5],[1,2,3,4,5]]
a.transpose.collect {|e| {:lt => e.first, :ln => e.last} }

Aurélien AMILIN

Le 07/04/2010 11:24, All4miller All4miller a écrit :

thanks that worked great

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs