feat: Add min and max and try to improve the performance

This commit is contained in:
rjianu
2023-07-17 20:18:16 +03:00
parent f837a1d217
commit 607561b9fe
9 changed files with 37 additions and 5 deletions

11
csv.go
View File

@@ -4,6 +4,7 @@ import (
"encoding/csv"
"fmt"
"io"
"sort"
"strconv"
)
@@ -21,6 +22,16 @@ func avg(data []float64) float64 {
return sum(data) / float64(len(data))
}
func min(data []float64) float64 {
sort.Float64s(data)
return data[0]
}
func max(data []float64) float64 {
sort.Float64s(data)
return data[len(data)-1]
}
func csv2float(r io.Reader, column int) ([]float64, error) {
cr := csv.NewReader(r)
// set this to reuse the same slice for each read