1
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.

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
Ross
  • 109
  • 2
  • 10

1 Answers1

5

Try:

output = Hash[array1.zip(array2)]
xdazz
  • 158,678
  • 38
  • 247
  • 274
  • 1
    Perfect, works fine with the example i provided in my question. But doesn't work if the values are same in array1 = [1,1,1,1] returns {1=>false} – Ross Mar 25 '14 at 08:06
  • @Ross Hash key should be unique, what is the expected result when array1 is `[1,1,1,1]` ? – xdazz Mar 25 '14 at 08:11