Exercise: count words
- Count how many times each word appears in a given slice
- You can use this skeleton:
package main
import (
"fmt"
)
func main() {
celestialObjects := []string{"Moon", "Gas", "Asteroid", "Dwarf", "Asteroid", "Moon", "Asteroid"}
fmt.Println(celestialObjects)
}
- Expected output:
[Moon Gas Asteroid Dwarf Asteroid Moon Asteroid]
Moon 2
Gas 1
Asteroid 3
Dwarf 1