package main
import (
"fmt"
)
func findMinMax[T comparable](arr []T) (min, max T) {
for _, v := range arr {
if v > max {
max = v
} else if v < min {
min = v
}
}
return min, max
}
func main() {
arr := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
fmt.Println(findMinMax(arr))
}
I would be more than happy to help you resolve the issue you are facing in the findMinMax function. The error message indicating that v > max or v < min suggests that there might be a problem with the comparison operation within the function. In order to offer a precise solution, I would need to see the implementation of the findMinMax function. Based on your description, it seems that the type T, which is supposed to be comparable, is causing the issue during comparison.
I am expecting the function findMinMax will work correctly.