Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go tour Exercise: Maps bug #21889

Closed
rahwang opened this issue Sep 14, 2017 · 3 comments
Closed

Go tour Exercise: Maps bug #21889

rahwang opened this issue Sep 14, 2017 · 3 comments

Comments

@rahwang
Copy link

rahwang commented Sep 14, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

This is a bug in the Go Tour on the website, so latest version I assume.

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

Windows

What did you do?

This word count code is "incorrect" according to the test suite which expects a value of 1 for all words.

func WordCount(s string) map[string]int {
words := strings.Fields(s);

fmt.Printf("%T, %d\n", words, len(words))
fmt.Println(words)

var result = make(map[string]int)
for _, v := range words {
	result[v] = len(v)
}
return result

}

What did you expect to see?

A test pass

What did you see instead?

A test fail

@ghost
Copy link

ghost commented Sep 14, 2017

There's a bug in your code; replace result[v] = len(v) with result[v]++.

@ianlancetaylor
Copy link
Member

I don't see problem here.

@rahwang
Copy link
Author

rahwang commented Sep 14, 2017

Ah, I misunderstood. The tour asks for count of word instances, not count of characters per word

@golang golang locked and limited conversation to collaborators Sep 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants