Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
> elements = {a1: 'a', b1: 'b', b2: 'b', b3: 'b', c1: 'c'}
=> {:a1=>"a", :b1=>"b", :b2=>"b", :b3=>"b", :c1=>"c"}
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b2, "b"], [:b3, "b"], [:b1, "b"], [:c1, "c"]]
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b1, "b"], [:b3, "b"], [:b2, "b"], [:c1, "c"]]
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b1, "b"], [:b3, "b"], [:b2, "b"], [:c1, "c"]]
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b2, "b"], [:b1, "b"], [:b3, "b"], [:c1, "c"]]
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b3, "b"], [:b2, "b"], [:b1, "b"], [:c1, "c"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.