slices/reverse.go

11 lines
177 B
Go
Raw Permalink Normal View History

2022-08-21 13:52:53 +02:00
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
2022-08-21 14:08:25 +02:00
s[ri] = slice[i]
2022-08-21 13:52:53 +02:00
}
return s
}