commit | 1f35091e41e1708641f2857d4adb42721e119add | [log] [tgz] |
---|---|---|
author | Kamil Kisiel <kamil@kamilkisiel.net> | Mon Apr 20 13:46:59 2015 -0700 |
committer | Kamil Kisiel <kamil@kamilkisiel.net> | Mon Apr 20 13:46:59 2015 -0700 |
tree | 892b34a4c5ec59a9107bf818c8087b12eaa580e6 | |
parent | 90d88c0e509c74a5d8d342022fa97f78b7bbabfa [diff] [blame] |
Added example of reversing
diff --git a/SliceTricks.md b/SliceTricks.md index 773f8f5..9b43224 100644 --- a/SliceTricks.md +++ b/SliceTricks.md
@@ -115,4 +115,15 @@ b = append(b, x) } } +``` + +### Reversing + +To replace the contents of a slice with the same elements but in reverse order: +```go + +for i := 0; i < len(a)/2; i++ { + opp := len(a)-1-i + a[i], a[opp] = a[opp], a[i] +} ``` \ No newline at end of file