For example
Given an array:
array = [[:a,:b],[:a,:c],[:c,:b]]
Return the following hash:
hash = { :a => [:b,:c] , :c => [:b] }
hash = Hash[array] overwrites previous associations, producing:
hash = { :a => :c , :c => :b }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using functional baby steps:
Using imperative style programming:
As an imperative one-liner:
Or using everyone’s favorite
inject:If you really want to have single values not collided as an array, you can either un-array them as a post-processing step, or use a different hash accumulation strategy that only creates an array upon collision. Alternatively, wrap your head around this: