Sha256: 271614450f74e2cdc82e35d8612fae3aa511b0079323214bdf3d6a3d093f053e
Contents?: true
Size: 394 Bytes
Versions: 13
Compression:
Stored size: 394 Bytes
Contents
# Taken from: https://github.com/rubyworks/facets/blob/master/lib/core/facets/array/mode.rb#L14 class Array # Get most common value from an array # If there is a tie for most common, an array is returned of the tied values 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
13 entries across 13 versions & 1 rubygems