2

I need to create a new Hash object using two arrays.

But, the conditions is first array value should be a key value for the Hash and second array value should be the Hash value.

a = ["x", "y"] 
b = [2, 4]

Result should be: c = {"x" => 2, "y" => 4}

1

1 Answer 1

12
irb(main):001:0> a = ["x", "y"]; b = [2, 4]
=> [2, 4]
irb(main):002:0> Hash[a.zip(b)]
=> {"x"=>2, "y"=>4}
Sign up to request clarification or add additional context in comments.

1 Comment

Hey, I'm just joking.. "Ruby" have the answers for all the Questions. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.