feat: add Reverse function to slice (#2381)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2023-05-24 16:53:44 +08:00
parent e1113c17c5
commit 72ac0c0adf
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 7 additions and 0 deletions

View File

@ -55,3 +55,10 @@ func RemoveDuplicates[T comparable](s []T) []T {
return result return result
} }
// Reverse reverses elements in a collection.
func Reverse[S ~[]T, T any](s S) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}