Sha256: 5f2dcafd61d89a2b90cd99326fa377de30f46255df1a68eca05c49c5c59e6e9c
Contents?: true
Size: 324 Bytes
Versions: 2
Compression:
Stored size: 324 Bytes
Contents
module Enumerable # Returns the first-appearing duplicate of each element, preserving # order of appearance. # # @example # %w[a a b c c b a d].duplicates # == ["a", "c", "b"] # # @return [Enumerable] def duplicates seen = Hash.new(0) self.select{|element| (seen[element] += 1) == 2 } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
casual_support-4.0.0 | lib/casual_support/enumerable/duplicates.rb |
casual_support-3.0.2 | lib/casual_support/enumerable/duplicates.rb |