Skip to content

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

@kkruups

Description

@kkruups

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 ")
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions