diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..73b4971 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module min-max + +go 1.21.6 diff --git a/main.go b/main.go new file mode 100644 index 0000000..95d71d1 --- /dev/null +++ b/main.go @@ -0,0 +1,25 @@ +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 +}