min-max-array/main.go

26 lines
388 B
Go

package minmax
// Returns either the largest value or the smallest value of an array
// TODO: Handle empty arrays without panicking
func Min(arr []float64) (min float64) {
min = arr[0]
for _, v := range arr {
if v < min {
min = v
}
}
return min
}
func Max(arr []float64) (max float64) {
max = arr[0]
for _, v := range arr {
if v > max {
max = v
}
}
return max
}