Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/ext.rb
Instance Method Summary collapse
Instance Method Details
#avg ⇒ Object
61 62 63 64 |
# File 'lib/ext.rb', line 61 def avg s, n = self.sum_with_number return s / n end |
#sum ⇒ Object
57 58 59 60 |
# File 'lib/ext.rb', line 57 def sum s, n = self.sum_with_number return s end |
#sum_with_number ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ext.rb', line 66 def sum_with_number return nil, 0 if(self.size <= 0) s = nil n = 0 self.each do |v| next if v.nil? if(s==nil) s = v else s += v end n += 1 end return s, n end |