#Why cannot print a sorted slice?

4 messages · Page 1 of 1 (latest)

lethal forum
#

Hi,

I'm sorting a slice using the sort.Strings function but somehow I cannot print it because of the error: sort.Strings(fa) (no value) used as valuecompiler

func sortElementsByKey() {
    fa := []string{}
    for k, _ := range familyAge {
        fa = append(fa, k)
    }
    fmt.Println(fa)
    sort.Strings(fa)
    fmt.Println(sort.Strings(fa))
}
cursive craterBOT
#

    func Strings(x []string)

Strings sorts a slice of strings in increasing order.

Note: consider using the newer slices.Sort function, which runs faster.

olive tundra
#

as you can see sort.Strings doesn't return anything

#

it just sorts x in place