github.com/blend/go-sdk@v1.20220411.3/mathutil/min.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  // Min finds the lowest value in a slice.
    11  func Min(input []float64) float64 {
    12  	if len(input) == 0 {
    13  		return 0
    14  	}
    15  
    16  	min := input[0]
    17  	for i := 1; i < len(input); i++ {
    18  		if input[i] < min {
    19  			min = input[i]
    20  		}
    21  	}
    22  	return min
    23  }
    24  
    25  // MinInts finds the lowest value in a slice.
    26  func MinInts(input []int) int {
    27  	if len(input) == 0 {
    28  		return 0
    29  	}
    30  
    31  	min := input[0]
    32  	for i := 1; i < len(input); i++ {
    33  		if input[i] < min {
    34  			min = input[i]
    35  		}
    36  	}
    37  	return min
    38  }