module MoreCoreExtensions::ArrayElementCounts

Public Instance Methods

element_counts() click to toggle source

Returns a Hash of each element to the count of those elements.

[1, 2, 3, 1, 3, 1].counts  # => {1 => 3, 2 => 1, 3 => 2}
# File lib/more_core_extensions/core_ext/array/element_counts.rb, line 6
def element_counts
  each_with_object(Hash.new(0)) { |i, h| h[i] += 1 }
end