Fix minBy

This commit is contained in:
世界 2022-08-12 12:10:20 +08:00
parent 735372ab3c
commit 13f394e202
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -194,6 +194,7 @@ func MinBy[T any, C constraints.Ordered](arr []T, block func(it T) C) T {
return min
}
min = arr[0]
minValue = block(min)
for i := 1; i < len(arr); i++ {
item := arr[i]
value := block(item)
@ -212,6 +213,7 @@ func MaxBy[T any, C constraints.Ordered](arr []T, block func(it T) C) T {
return max
}
max = arr[0]
maxValue = block(max)
for i := 1; i < len(arr); i++ {
item := arr[i]
value := block(item)