From: Jamey Cribbs Date: 2006-10-13T01:22:06+09:00 Subject: Re: Isolating non-unique items in an array 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. > > Here's what I whipped up: letters = ['a','a','a','b','c','d','d'] counts = {} letters.each do |letter| count = letters.find_all { |x| x == letter }.size counts[letter] = count if count > 1 end non_unique_letters = letters.find_all { |x| counts.has_key?(x) } p counts p non_unique_letters Jamey Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.