How do I check an array for duplicates?

<>

This question already has an answer here:

Answers


Just call uniq on it (which returns a new array without duplicates) and see whether the uniqed array has less elements than the original:

if a.uniq.length == a.length
  puts "a does not contain duplicates"
else
  puts "a does contain duplicates"
end

Note that the objects in the array need to respond to hash and eql? in a meaningful for uniq to work properly.


Need Your Help

Extracting table data from html with python and BeautifulSoup

python html beautifulsoup

I'm new with python and beautifulsopu lib. I have tried many things, but no luck.

Perl: Simple INI file info retrieval

perl file config ini

I have a perl script that's reading an INI file like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.