Sha256: 178971ff5ee8c7533523adea81e0d2c8c73744c36b64ec77dd779b13b6fe01bc

Contents?: true

Size: 423 Bytes

Versions: 6

Compression:

Stored size: 423 Bytes

Contents

# frozen_string_literal: true

class Array
  def subsequences
    (0..length).map do |n|
      self[0, n]
    end
  end

  def duplicates
    group_by(&:itself).map { |e| e[0] if e[1][1] }.compact
  end

  def deep_compact!
    each do |v|
      if v.is_a?(Hash) || v.respond_to?(:values)
        v.values.deep_compact!
      elsif v.is_a?(Array) || v.respond_to?(:each)
        v.deep_compact!
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
modern-0.5.0 lib/modern/core_ext/array.rb
modern-0.4.6 lib/modern/core_ext/array.rb
modern-0.4.5 lib/modern/core_ext/array.rb
modern-0.4.4 lib/modern/core_ext/array.rb
modern-0.4.3 lib/modern/core_ext/array.rb
modern-0.4.2 lib/modern/core_ext/array.rb