github.com/blend/go-sdk@v1.20220411.3/mathutil/max.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package mathutil 9 10 // Max finds the highest value in a slice. 11 func Max(input []float64) float64 { 12 if len(input) == 0 { 13 return 0 14 } 15 16 max := input[0] 17 18 for i := 1; i < len(input); i++ { 19 if input[i] > max { 20 max = input[i] 21 } 22 } 23 24 return max 25 } 26 27 // MaxInts finds the highest value in a slice. 28 func MaxInts(input []int) int { 29 if len(input) == 0 { 30 return 0 31 } 32 33 max := input[0] 34 35 for i := 1; i < len(input); i++ { 36 if input[i] > max { 37 max = input[i] 38 } 39 } 40 41 return max 42 }