That would also enable you to pass in a float as an argument to the func instead of a string as well.
Don't forget to include logic for checking if they have exact change!
If you would still like me to post a solution using a map I would be more than happy to.
Note
In Golang, if you attempt to access a value of a map with a key that doesn't exist, you will get the zero value of the type stored in the map. That may be useful for the exact change logic check in your solution.
If we use your map for example:
types[5.0]
would return "", since the key 5.0 doesn't exist and "" is the zero value for a string in Golang.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hello Cherny!
You can most certainly use floats as keys in a map, you just need to indicate what type the keys are in the map declaration.
For your code above you have:
If you want to use floats as the keys, you simply need to indicate as so:
Then you could so something like this:
That would also enable you to pass in a float as an argument to the func instead of a string as well.
Don't forget to include logic for checking if they have exact change!
If you would still like me to post a solution using a map I would be more than happy to.
Note
In Golang, if you attempt to access a value of a map with a key that doesn't exist, you will get the zero value of the type stored in the map. That may be useful for the exact change logic check in your solution.
If we use your map for example:
would return "", since the key 5.0 doesn't exist and "" is the zero value for a string in Golang.