문제

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.

도움이 되었습니까?

해결책

Try:

output = Hash[array1.zip(array2)]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top