From 8a811a7e20c616806ba824e083595e83be9afb40 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Fri, 24 Jan 2025 11:06:24 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20Max()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- micro/microfunctions.go | 88 ++++++++++++++++++++++++++++-------- micro/microfunctions_test.go | 8 ++-- 2 files changed, 72 insertions(+), 24 deletions(-) diff --git a/micro/microfunctions.go b/micro/microfunctions.go index 1a07f092..850069cf 100644 --- a/micro/microfunctions.go +++ b/micro/microfunctions.go @@ -335,36 +335,84 @@ func Trim(s string) string { return Otvet } -// Max returns the largest of x or y. -func Max(x, y int) int { - if x < y { - return y +// Max returns the largest value +func Max(Mass ...int) int { + var Otvet int + + // + if len(Mass) == 0 { + return Otvet } - return x + + // + Otvet = Mass[0] + for _, val := range Mass { + if val > Otvet { + Otvet = val + } + } + + return Otvet } -// Min returns the smallest of x or y. -func Min(x, y int) int { - if x > y { - return y +// Min returns the smallest value +func Min(Mass ...int) int { + var Otvet int + + // + if len(Mass) == 0 { + return Otvet } - return x + + // + Otvet = Mass[0] + for _, val := range Mass { + if val < Otvet { + Otvet = val + } + } + + return Otvet } -// Max returns the largest of x or y. -func MaxInt64(x, y int64) int64 { - if x < y { - return y +// MaxInt64 returns the largest value +func MaxInt64(Mass ...int64) int64 { + var Otvet int64 + + // + if len(Mass) == 0 { + return Otvet } - return x + + // + Otvet = Mass[0] + for _, val := range Mass { + if val > Otvet { + Otvet = val + } + } + + return Otvet } -// Min returns the smallest of x or y. -func MinInt64(x, y int64) int64 { - if x > y { - return y +// MinInt64 returns the smallest value +func MinInt64(Mass ...int64) int64 { + var Otvet int64 + + // + if len(Mass) == 0 { + return Otvet } - return x + + // + Otvet = Mass[0] + for _, val := range Mass { + if val < Otvet { + Otvet = val + } + } + + return Otvet } // MaxDate returns the largest of x or y. diff --git a/micro/microfunctions_test.go b/micro/microfunctions_test.go index 7014ac7a..262c7084 100644 --- a/micro/microfunctions_test.go +++ b/micro/microfunctions_test.go @@ -205,15 +205,15 @@ func TestMin(t *testing.T) { } } -func TestMaxInt60(t *testing.T) { - Otvet := MaxInt64(1, 2) - if Otvet != 2 { +func TestMaxInt64(t *testing.T) { + Otvet := MaxInt64(1, 2, 3, 4) + if Otvet != 4 { t.Error("microfunctions_test.TestMax() error: Otvet != 2") } } func TestMinInt64(t *testing.T) { - Otvet := MinInt64(1, 2) + Otvet := MinInt64(1, 2, 3, 4) if Otvet != 1 { t.Error("microfunctions_test.TestMin() error: Otvet != 1") }