mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-11 07:41:18 +00:00
Mutations
Insert and element
m[key] = elem
Get an element
elem = m[key]
Delete an element
delete(m, key)
Check if a key exists
elem, ok := m[key]
If key is in m, then ok is true. If not, ok is false.
If key is not in the map, then elem is the zero value for the map's element type.
Assignment
It's important to keep up with privacy regulations and to respect our user's data. We need a function that will delete user records.
Complete the deleteIfNecessary function.
- If the user doesn't exist in the map, return the error
not found. - If they exist but aren't scheduled for deletion, return
deletedasfalsewith no errors. - If they exist and are scheduled for deletion, return
deletedastruewith no errors and delete their record from the map.
Note on passing maps
Like slices, maps are also passed by reference into functions. This means that when a map is passed into a function we write, we can make changes to the original, we don't have a copy.