From 309cb67bda3883130d0232120a301cbaf1605206 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 30 Jan 2024 19:17:19 +0100 Subject: [PATCH] Startup Adding primary files --- go.mod | 3 +++ main.go | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 go.mod create mode 100644 main.go 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 +}