Fixed crashing when handling empty arrays
This commit is contained in:
parent
10e172b29f
commit
41c2fcc5af
6
main.go
6
main.go
|
@ -5,6 +5,9 @@ package minmax
|
|||
// TODO: Handle empty arrays without panicking
|
||||
|
||||
func Min(arr []float64) (min float64) {
|
||||
if len(arr) == 0 {
|
||||
return 0
|
||||
}
|
||||
min = arr[0]
|
||||
for _, v := range arr {
|
||||
if v < min {
|
||||
|
@ -15,6 +18,9 @@ func Min(arr []float64) (min float64) {
|
|||
}
|
||||
|
||||
func Max(arr []float64) (max float64) {
|
||||
if len(arr) == 0 {
|
||||
return 0
|
||||
}
|
||||
max = arr[0]
|
||||
for _, v := range arr {
|
||||
if v > max {
|
||||
|
|
Loading…
Reference in New Issue