Sha256: a36ef9cf89114d134a6fd702ef353c88a23d69131e0e353c6735134175ee79b2

Contents?: true

Size: 365 Bytes

Versions: 2

Compression:

Stored size: 365 Bytes

Contents

# -*- encoding: utf-8 -*-
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-

class Array
  # Returns an array of the duplicate elements.
  #
  # ==== Examples
  #
  #   [1, 2, 3, 2, 4, 1, 5].duplicates #=> [1, 2]
  #   [1, 2, 3, 4, 2, 4].duplicates    #=> [2, 4]
  def duplicates
    self.select { |element| self.count(element) > 1 }.uniq
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rb_core_extensions-0.1.3 lib/core_extensions/array/duplicates.rb
rb_core_extensions-0.1.2 lib/core_extensions/array/duplicates.rb