mirror of
https://github.com/samber/lo.git
synced 2025-09-26 20:11:13 +08:00
14 lines
412 B
Go
14 lines
412 B
Go
package mutable
|
|
|
|
// Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
|
|
// Play: https://go.dev/play/p/iv2e9jslfBM
|
|
func Reverse[T any, Slice ~[]T](collection Slice) {
|
|
length := len(collection)
|
|
half := length / 2
|
|
|
|
for i := 0; i < half; i = i + 1 {
|
|
j := length - 1 - i
|
|
collection[i], collection[j] = collection[j], collection[i]
|
|
}
|
|
}
|