To find the range of all values in a map in Go, you can use a combination of range loop and a couple of helper functions. Here is an example:
main.go255 chars13 lines
In this function, we use the range loop to iterate through all the values in the map. For each value, we check if it is less than the current minimum or greater than the current maximum. If either of these conditions is true, we update the minimum and maximum values accordingly.
To use this function, simply pass your map as an argument and capture the return values:
main.go124 chars4 lines
This will output: Range: 5-20
.
gistlibby LogSnag