I have the following array and I want to convert it a hash with keys as age and values like the name of the person. Additionally, I want to make sure that folks of the same age belong to the same key.
ages = [ ['alpha', 20], ['beta',21], ['charlie',23], ['delta', 20] , ['gamma', 23]]
how do I convert the above into a hash like below?
eg - {20 => ['alpha','delta'] } etc.
i have tried the following code but i am getting stuck beyond this point:
hash = Hash[ages.collect {|item| [item[1], item[0]]} ]
pp hash
thank you.