To find the range of a list of numbers in Go, you can use a for loop to iterate through the list and keep track of the minimum and maximum values you encounter. Here's an example:
main.go247 chars14 lines
In this function, we initialize min
and max
to the first value in the list. Then for each subsequent value in the list, we compare it to min
and max
and update their values if necessary. Finally, we return the minimum and maximum values as a tuple.
You can call this function with a slice of integers to find its range:
main.go114 chars4 lines
This will output:
main.go11 chars2 lines
gistlibby LogSnag