From 41c2fcc5af7037445826f2e39ba19988f289ab0c Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 31 Jan 2024 10:57:39 +0000 Subject: [PATCH] Fixed crashing when handling empty arrays --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index 2a7669a..cae94ff 100644 --- a/main.go +++ b/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 {