Module: MiniFacet::CountDistinct

Defined in:
lib/mini_facet/array/count_distinct.rb

Overview

Can be included in any class that responds to #each. Such as Array.

Instance Method Summary collapse

Instance Method Details

#count_distinct(purge_smaller_than = 0) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/mini_facet/array/count_distinct.rb', line 4

def count_distinct(purge_smaller_than=0)
  h={}
  self.each {|e|
    h[e] ? h[e] += 1 : h[e] = 1
  }
  h.extract{|k,v| v >= purge_smaller_than}
end