I have a hash like this:
h={
:p1 => [:c1,:c2],
:p2 => [:c3,:c4],
:p3 => [:c1,:c5],
:p4 => [:c3,:c2],
:p5 => [:c6,:c7]
}
I’d like to find a nice Ruby function that returns an array of arrays like this:
res=[[:p1,:p3],[:p2,:p4]]
Each sub-array is made of hash keys whose first values associated are equal: :p1 and :p3 have :c1 as a starting value, and :p2 and :p4 have :c3.
How’s this?