Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/fnordmetric/ext.rb
Instance Method Summary collapse
- #emtpy ⇒ Object
- #mean ⇒ Object (also: #average)
- #median ⇒ Object
- #mode ⇒ Object
- #range ⇒ Object
Instance Method Details
#emtpy ⇒ Object
60 61 62 |
# File 'lib/fnordmetric/ext.rb', line 60 def emtpy self.size == 0 end |
#mean ⇒ Object Also known as: average
37 38 39 40 |
# File 'lib/fnordmetric/ext.rb', line 37 def mean return 0 if empty? inject(&:+).to_f / size end |
#median ⇒ Object
44 45 46 47 |
# File 'lib/fnordmetric/ext.rb', line 44 def median return 0 if empty? (_sorted = self.dup.sort)[_sorted.size/2] end |
#mode ⇒ Object
54 55 56 57 58 |
# File 'lib/fnordmetric/ext.rb', line 54 def mode return 0 if empty? inject({}){ |h,v| h[v] = h[v].to_i+1; h }.to_a .sort{ |a,b| b.last <=> a.last }[0][0] end |
#range ⇒ Object
49 50 51 52 |
# File 'lib/fnordmetric/ext.rb', line 49 def range return 0 if empty? max - min end |