Standard library / sort

sort.IntSlice.Less()

Reports whether the element at i precedes the element at j. Indices must be valid. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func (x IntSlice) Less(i, j int) bool

Parameters & Attributes

NameTypeDescription
iintIndex or start position.
jintSecond index or exclusive end position.

Return Value

bool

Reports whether the element at i precedes the element at j. Indices must be valid.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sort")
func main() {  a := sort.IntSlice([]int{1, 2, 3})  fmt.Println(a.Less(0, 1), a.Less(1, 0))}
Go Reference