From: Paul Lutus Date: 2006-10-28T02:50:20+09:00 Subject: Re: how to get only the duplicatet items from an array Nico Landgraf wrote: > i have an array like this > aTemp = [1, 1, 2, 2, 3, 4] > and i want to know, which items are duplicatet. / ... > so i found an bad solution and hope you can help me to get the right way. #!/usr/bin/ruby -w a = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9] dups = [] hash = {} a.each do |item| dups << item if hash[item] hash[item] = true end p dups [1, 1, 1, 1, 2, 2, 2, 9, 9] -- Paul Lutus http://www.arachnoid.com