Complete the code to declare a hash table (map) in Go that maps strings to integers.
var scores [1]In Go, a hash table is called a map. The syntax map[string]int means keys are strings and values are integers.
Complete the code to insert a key-value pair into the hash table.
scores["Alice"] = [1]
To insert a value into a map, assign the value to the key. Here, 100 is the value for key "Alice".
Fix the error in the hash function that returns the index for a given key.
func hash(key string, size int) int {
var sum int
for _, char := range key {
sum += int(char)
}
return sum [1] size
}The hash function should use the modulo operator (%) to ensure the index fits within the table size.
Fill both blanks to complete the function that checks if a key exists in the hash table.
func exists(table map[string]int, key string) bool {
_, [1] := table[key]
return [2]
}In Go, when accessing a map, the second returned value indicates if the key exists. We store it in a variable (commonly named found) and return it.
Fill all three blanks to complete the function that deletes a key from the hash table if it exists.
func deleteKey(table map[string]int, key string) {
_, [1] := table[key]
if [2] {
[3](table, key)
}
}The second value from map access is stored in 'found'. If found is true, we use the built-in delete function to remove the key.
