Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio-standards/utilities/array.rb

Overview

Instance Method Summary collapse

Instance Method Details

#modeObject

Get most common value from an array If there is a tie for most common, an array is returned of the tied values



5
6
7
8
9
10
# File 'lib/openstudio-standards/utilities/array.rb', line 5

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