Go Package slices: Difference between revisions
Jump to navigation
Jump to search
(→Sort()) |
|||
Line 14: | Line 14: | ||
s := []int{0, 42, -10, 8} | s := []int{0, 42, -10, 8} | ||
slices.Sort(s) | slices.Sort(s) | ||
</syntaxhighlight> | |||
==<tt>Contains()</tt>== | |||
{{External|https://pkg.go.dev/slices#Contains}} | |||
<syntaxhighlight lang='go'> | |||
s := []int{0, 42, -10, 8} | |||
slices.Contains(s) | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 22:55, 26 April 2024
External
Internal
Overview
Sorting
Sort()
Sort()
inplace sorts a slice of any ordered type in ascending order. When sorting floating-point numbers, NaNs are ordered before other values.
s := []int{0, 42, -10, 8}
slices.Sort(s)
Contains()
s := []int{0, 42, -10, 8}
slices.Contains(s)