From: Drew Olson Date: 2006-10-13T01:05:09+09:00 Subject: Re: Isolating non-unique items in an array Drew Olson wrote: > Jason Burgett wrote: >> I'm basically trying to the opposite of .uniq Let's say I have an array: >> >> ["a", "a", "a", "b", "c", "d", "d"] >> >> I would like to boil this down by first tossing the values that only >> appear once. Which leaves me with: >> >> ["a", "a", "a", "d", "d"] >> >> Then I need to somehow determine that "a" appears 3 times and "d" >> appears 2 times. Any help would be great. Thanks > > This should work: > > a = ["a", "a", "a", "b", "c", "d", "d"] > a.uniq.map{|i| i if (a.map{|j| j if j==i}.length > 1)} Actually, so that you have them appear more than once you'd need to do: a = ["a", "a", "a", "b", "c", "d", "d"] a.map{|i| i if (a.map{|j| j if j==i}.length > 1)} -- Posted via http://www.ruby-forum.com/.