从Ruby中的数组中删除重复元素

问题描述:

我有一个包含重复元素的 Ruby 数组.

I have a Ruby array which contains duplicate elements.

array = [1,2,2,1,4,4,5,6,7,8,5,6]

如何在不使用 for 循环和迭代的情况下从该数组中删除所有重复元素,同时保留所有唯一元素?

How can I remove all the duplicate elements from this array while retaining all unique elements without using for-loops and iteration?

array = array.uniq

uniq 删除所有重复元素并保留数组中的所有唯一元素.

uniq removes all duplicate elements and retains all unique elements in the array.

这是 Ruby 语言的众多优点之一.

This is one of many beauties of the Ruby language.