min-max-array/main.go

26 lines
388 B
Go
Raw Normal View History

2024-01-30 19:42:25 +01:00
package minmax
2024-01-30 19:17:19 +01:00
// 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
}