Ross
Ross

Reputation: 109

Convert 2 arrays to 1 hash

array1 = [1,2,3,4]

array2 = [true,false,true,false]

expected output : [:1 => true, :2 => false, :3 => true, :4 => false]    

Would like to make the array1 values as keys of the hash and array2 values as the hash values.

Using ruby 1.8

Can someone please help how to achieve this.

Upvotes: 1

Views: 151

Answers (1)

xdazz
xdazz

Reputation: 160883

Try:

output = Hash[array1.zip(array2)]

Upvotes: 5

Related Questions