Here's how to find the average of all values in a HashMap in Rust:
main.rs527 chars18 lines
This code first creates a HashMap with some initial values. Then it calculates the sum of all values using the values()
method of the HashMap, which returns an iterator of all values in the map. The sum()
method from the standard library is called on this iterator to calculate the total sum of all values. The number of values in the map is then obtained using the len()
method, and the average is simply the sum divided by the number of values in the map. The result is printed to the console.
gistlibby LogSnag