Reputation: 363
I have the following:
array = ["John", "Mike", "Bob", "Mike", "Bob"]
i want to get output:
[["Mike", "Mike"], ["Bob", "Bob"], ["John"]]
Upvotes: 29
Views: 17002
Reputation: 168101
Here is how to do that in Ruby.
array.group_by{ |x| x }.values
Upvotes: 55