Standard library / slices

slices.IsSorted()

Checks ascending order, treating floating-point NaNs as preceding non-NaNs. Expected stdout: 'true false\n'.

Formal Syntax & Structure

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

Parameters & Attributes

NameTypeDescription
xSInput value or collection to process.

Return Value

bool

Checks ascending order, treating floating-point NaNs as preceding non-NaNs.

Working Example

Example Snippetgo
package main
import (  "fmt"  "slices")
func main() {  fmt.Println(slices.IsSorted([]int{1, 2, 2}), slices.IsSorted([]int{2, 1}))}
Go Reference