26 lines
386 B
Go
26 lines
386 B
Go
|
package main
|
||
|
|
||
|
// 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
|
||
|
}
|