Standard library / sort
sort.Reverse()
Wraps a sort.Interface with its Less ordering reversed; does not itself rearrange elements. Expected stdout: '[3 2 1]\n'.
Formal Syntax & Structure
go syntaxgo
func Reverse(data Interface) InterfaceParameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | Interface | Collection implementing sort.Interface. |
Return Value
Interface
Wraps a sort.Interface with its Less ordering reversed; does not itself rearrange elements.
Working Example
Example Snippetgo
package main
import ( "fmt" "sort")
func main() { a := sort.IntSlice{1, 3, 2} sort.Sort(sort.Reverse(a)) fmt.Println(a)}