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

Functions as Data section: change var name from "key" to "index" #56

Open
kkruups opened this issue Mar 4, 2016 · 0 comments
Open

Functions as Data section: change var name from "key" to "index" #56

kkruups opened this issue Mar 4, 2016 · 0 comments

Comments

@kkruups
Copy link

kkruups commented Mar 4, 2016

Hi Yuuta,

In section "Functions As Data" you wrote the code below. Since activity is a slice and not a map you should refrain from using the word variable name "key", instead use variable name "index", since keys are associated with maps not slices or arrays.

Changing the name will make your code much easier to read and understand.

You wrote:

func compose(p phrases, a []activity) (func()){
    return func(){
        for key, value := range a{
            fmt.Print(p[value])
            if key == len(a)-1{
                fmt.Println(".")
            } else {
                fmt.Print(" and ")
            }
        }
    }
}

Should be corrected in following manner (see use of variable name "index" in place of "key")

func compose(p phrases, a []activity) (func()){
    return func(){
        for index, value := range a{
            fmt.Print(p[value])
            if index == len(a)-1{
                fmt.Println(".")
            } else {
                fmt.Print(" and ")
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant