Skip to content

Instantly share code, notes, and snippets.

@bsolomon1124
Created September 4, 2018 01:55
Show Gist options
  • Save bsolomon1124/f42ea7ef9b07c574c66f0ccf201211f5 to your computer and use it in GitHub Desktop.
Save bsolomon1124/f42ea7ef9b07c574c66f0ccf201211f5 to your computer and use it in GitHub Desktop.
package variadic
// Platform-dependent largest and smallest values that int may take on
const (
LargestInt = int(^uint(0) >> 1)
SmallestInt = -1 * int(^uint(0) >> 1) - 1
)
func Min(a ...int) int {
min := LargestInt
for _, i := range a {
if i < min {
min = i
}
}
return min
}
func Max(a ...int) int {
max := SmallestInt
for _, i := range a {
if i > max {
max = i
}
}
return max
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment