In Ruby, given an array in one of the following forms...
[apple, 1, banana, 2] [[apple, 1], [banana, 2]]
...what is the best way to convert
Not sure if it's the best way, but this works:
a = ["apple", 1, "banana", 2] m1 = {} for x in (a.length / 2).times m1[a[x*2]] = a[x*2 + 1] end b = [["apple", 1], ["banana", 2]] m2 = {} for x,y in b m2[x] = y end