slices/reverse.go
2022-08-21 14:08:25 +02:00

11 lines
177 B
Go

package slices
func Reverse[T any](slice []T) []T {
s := make([]T, len(slice))
for i := 0; i < len(slice); i++ {
ri := len(slice) - 1 - i
s[ri] = slice[i]
}
return s
}