Sha256: bf22f4efc7b0bca287203320570b314dd0c37abf0a4bb6892aed1a8b595bd0c7

Contents?: true

Size: 375 Bytes

Versions: 1

Compression:

Stored size: 375 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

1 entries across 1 versions & 1 rubygems

Version Path
rb_core_extensions-0.1.1 lib/core_extensions/array/duplicates.rb