Source file tour/solutions/maps.go

     1  //go:build OMIT
     2  
     3  // Copyright 2012 The Go Authors.  All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import (
    10  	"strings"
    11  
    12  	"golang.org/x/tour/wc"
    13  )
    14  
    15  func WordCount(s string) map[string]int {
    16  	m := make(map[string]int)
    17  	for _, f := range strings.Fields(s) {
    18  		m[f]++
    19  	}
    20  	return m
    21  }
    22  
    23  func main() {
    24  	wc.Test(WordCount)
    25  }
    26  

View as plain text