// Reverse reverses any slice of any type.
func ReverseInplace[T any](arr []T) {
n := len(arr)
for i := 0; i < n/2; i++ {
arr[i], arr[n-1-i] = arr[n-1-i], arr[i]
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter