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

Version Path
openstudio-standards-0.7.0 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.7.0.rc1 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.6.3 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.6.0.rc2 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.6.0.rc1 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.5.0 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.5.0.rc1 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.4.0 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.3.1.rc2 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.3.1.rc1 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.3.0 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.2.17.rc2 lib/openstudio-standards/utilities/array.rb
openstudio-standards-0.2.17.rc1 lib/openstudio-standards/utilities/array.rb