Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/util/Comp.rb

Instance Method Summary collapse

Instance Method Details

#maxObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/util/Comp.rb', line 12

def max
    m = self[0]

    self.each do |i|
        if i > m
            m = i
        end
    end

    m
end

#meanObject



36
37
38
# File 'lib/util/Comp.rb', line 36

def mean
    self.sum/self.size.to_f
end

#minObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/util/Comp.rb', line 24

def min
    m = self[0]

    self.each do |i|
        if i < m
            m = i
        end
    end

    m
end

#sumObject



2
3
4
5
6
7
8
9
10
# File 'lib/util/Comp.rb', line 2

def sum
    s = 0

    self.each do |i|
        s += i
    end

    s
end