Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下内容:
array = ["John", "Mike", "Bob", "Mike", "Bob"]
我想得到输出:
[["Mike", "Mike"], ["Bob", "Bob"], ["John"]]
以下是如何在 Ruby 中执行此操作。
array.group_by{ |x| x }.values