

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Maps
incomplete
2: Mutations
incomplete
3: Key Types
incomplete
4: Count Instances
incomplete
5: Effective Go
incomplete
6: Nested
incomplete
7: Distinct Words
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Remember that you can check if a key is already present in a map by using the second return value from the index operation.
You can combine an if statement with an assignment operation to use the variables inside the if block:
names := map[string]int{}
missingNames := []string{}
if _, ok := names["Denna"]; !ok {
// if the key doesn't exist yet,
// append the name to the missingNames slice
missingNames = append(missingNames, "Denna")
}
Each time a user is sent a message, their username is logged in a slice. We want a more efficient way to count how many messages each user received.
Implement the updateCounts function. It takes as input:
messagedUsers: a slice of strings.validUsers: a map of string -> int.It should update the validUsers map with the number of times each user has received a message. Each string in the slice is a username, but they may not be valid. Only update the message count of valid users.
So, if "benji" is in the map and appears in the slice 3 times, the key "benji" in the map should have the value 3.