mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
New similarity.CompareTracks function
This commit is contained in:
parent
bace31471e
commit
b2b5c69278
4 changed files with 110 additions and 2 deletions
|
@ -32,3 +32,19 @@ func Min[T constraints.Ordered](m, n T) T {
|
|||
return m
|
||||
}
|
||||
}
|
||||
|
||||
func Sum[T constraints.Integer | constraints.Float](v ...T) T {
|
||||
var sum T
|
||||
for _, i := range v {
|
||||
sum += i
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func Average[T constraints.Integer | constraints.Float](v ...T) float64 {
|
||||
length := len(v)
|
||||
if length == 0 {
|
||||
return 0.0
|
||||
}
|
||||
return float64(Sum(v...)) / float64(length)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue