Sha256: 136d10506549e2adb626f8d64c6bdbecd22c6c15f2485b6fb8ea6d1d1eda5bb5

Contents?: true

Size: 486 Bytes

Versions: 2

Compression:

Stored size: 486 Bytes

Contents

class Array

  # In Statistics. mode is the value that occurs most frequently
  # in a given set of data. This method returns an array in case
  # there is a tie.
  #
  #   [:a, :b, :c, :b, :d].mode  #=> [:b]
  #   [:a, :b, :c, :b, :a].mode  #=> [:a, :b]
  #
  # Returns an Array of most common elements.
  #
  # @author Robert Klemme

  def mode
    max = 0
    c = Hash.new 0
    each {|x| cc = c[x] += 1; max = cc if cc > max}
    c.select {|k,v| v == max}.map {|k,v| k}
  end

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/array/mode.rb
facets-3.1.0 lib/core/facets/array/mode.rb