1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-24 22:53:52 +02:00

сделал Max()

This commit is contained in:
Nikitin Aleksandr
2025-01-24 11:06:24 +03:00
parent c8b6ecda35
commit 8a811a7e20
2 changed files with 72 additions and 24 deletions

View File

@@ -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.

View File

@@ -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")
}