Array to Hash Ruby

Convert this Array:

a = ["item 1", "item 2", "item 3", "item 4"] 

…to a Hash:

{ "item 1" => "item 2", "item 3" => "item 4" }

i.e. elements at even indexes are keys and odd ones are values.

9 Answers
9

Leave a Comment