Summer camp puts every camper in a cabin; each one in campers has a Name and a Cabin. Write ByCabin(campers) to return a map from each cabin to the names staying in it (in their original order). Nobody gives an empty map.
ByCabin([]Camper{{"Li", "Oak"}, {"Bo", "Pine"}, {"Mia", "Oak"}})→{'Oak': ['Li', 'Mia'], 'Pine': ['Bo']}ByCabin([]Camper{})→{}func ByCabin(campers []Camper) map[string][]stringpackage main
type Camper struct {
Name string
Cabin string
}
func ByCabin(campers []Camper) map[string][]string {
cabins := map[string][]string{}
for _, c := range campers {
// your code here: add c.Name to the end of c.Cabin's list
}
return cabins
}
Run tries the examples. When they look right, Submit.