Skip to content

Commit

Permalink
feat: add Reverse function to slice (#2381)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi committed May 24, 2023
1 parent 04f2585 commit dec9948
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/slices/slices.go
Expand Up @@ -55,3 +55,10 @@ func RemoveDuplicates[T comparable](s []T) []T {

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]
}
}

0 comments on commit dec9948

Please sign in to comment.