Skip to content

Commit f7964b6

Browse files
committed
add min
2 parents 0508caa + ad530cd commit f7964b6

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

tut/stat/stat.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
type Stats struct {
1313
data []float64
14-
// TODO(kyle): Define , keep data hidden, hide internals and define clean,least surprising, no modifying function
1514
}
1615

1716
func (s *Stats) Add(x ...float64) { //append
@@ -55,22 +54,20 @@ func (s *Stats) Mean() float64 {
5554
return x
5655
}
5756

58-
func (s *Stats) Add(x ...float64) {
59-
s.data = append(s.data, x...)
60-
}
61-
func (s *Stats) Mean() float64 {
62-
var x float64
63-
x = 0
57+
func (s *Stats) Max() float64 {
58+
var max float64
59+
max = 0
6460
var i int
6561
for i = 0; i < len(s.data); i++ {
66-
x = x + s.data[i]
62+
if s.data[i] > max {
63+
max = s.data[i]
64+
}
6765
}
6866

69-
x = x / float64(len(s.data))
70-
return x
67+
return max
7168
}
7269

73-
func (s *Stats) Max() float64 {
70+
func (s *Stats) Min() float64 {
7471
var max float64
7572
max = 0
7673
var i int

0 commit comments

Comments
 (0)