Standard library / slices

slices.Max()

Returns the largest ordered element; panics on empty input and propagates floating-point NaN. Expected stdout: '8\n'.

Formal Syntax & Structure

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

Parameters & Attributes

NameTypeDescription
xSInput value or collection to process.

Return Value

E

Returns the largest ordered element; panics on empty input and propagates floating-point NaN.

Working Example

Example Snippetgo
package main
import (  "fmt"  "slices")
func main() {  fmt.Println(slices.Max([]int{8, 3, 5}))}
Go Reference