Method: Enumerable#duplicates

Defined in:
lib/casual_support/enumerable/duplicates.rb

#duplicatesEnumerable

Returns the first-appearing duplicate of each element, preserving order of appearance.

Examples:

%w[a a b c c b a d].duplicates  # == ["a", "c", "b"]

Returns:



10
11
12
13
# File 'lib/casual_support/enumerable/duplicates.rb', line 10

def duplicates
  seen = Hash.new(0)
  self.select{|element| (seen[element] += 1) == 2 }
end