Standard library / slices

slices.Reverse()

Reverses element order in place. Expected stdout: '[3 2 1]\n'.

Formal Syntax & Structure

go syntaxgo
func Reverse[S ~[]E, E any](s S)

Parameters & Attributes

NameTypeDescription
sSInput slice; may share its backing array.

Working Example

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