Sha256: 38e755264a62c38bdab40d7861e84f49735657e1926c4b8c5497f175196e8a9c

Contents?: true

Size: 264 Bytes

Versions: 4

Compression:

Stored size: 264 Bytes

Contents

class Array
  def mode
    if self.length <= 1
      return self
    end

    seen = Hash.new(0)

    self.each{ |value| seen[value] += 1 }

    max = seen.values.max

    seen.find_all{ |key, value| value == max }.map{ |key, value| key }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rstat-0.1.1 lib/rstat/core_ext/array/descriptive_statistics/location/mode.rb
rstat-0.1.0 lib/rstat/core_ext/array/descriptive_statistics/location/mode.rb
rstat-0.0.4 lib/rstat/core_ext/array/mode.rb
rstat-0.0.3 lib/rstat/core_ext/array/mode.rb