Skip to content

Instantly share code, notes, and snippets.

@hitzhangjie
Created August 23, 2020 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitzhangjie/a26d1c48801b08669c8cf14ae3870539 to your computer and use it in GitHub Desktop.
Save hitzhangjie/a26d1c48801b08669c8cf14ae3870539 to your computer and use it in GitHub Desktop.
reverse anything you could
func reverse(s interface{}) {
n := reflect.ValueOf(s).Len()
swap := reflect.Swapper(s)
for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
swap(i, j)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment