Standard library / slices

slices.Sort()

Sorts ordered values ascending in place; NaN precedes non-NaN. Stability is not promised. Expected stdout: '[1 2 3]\n'.

Formal Syntax & Structure

go syntaxgo
func Sort[S ~[]E, E cmp.Ordered](x S)

Parameters & Attributes

NameTypeDescription
xSInput value or collection to process.

Working Example

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