September 2017
Intermediate to advanced
466 pages
9h 33m
English
This section will illustrate the use of the sort.Slice() function that first came with Go version 1.8. The use of the function will be illustrated in sortSlice.go, which will be presented in three parts.
The first part is the expected preamble of the program and the definition of a new structure type, given as follows:
package main
import (
"fmt"
"sort"
)
type aStructure struct {
person string
height int
weight int
}
As you might expect, you have to import the sort package to be able to use its Slice() function.
The second part contains the definition of a slice, which has four elements:
func main() {
mySlice := make([]aStructure, 0)
a := aStructure{"Mihalis", 180, 90} mySlice = append(mySlice, a) a = aStructure{"Dimitris", ...Read now
Unlock full access