Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions basic/slice_/slice_reverse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package slice_

import "fmt"

func reverseInts(s []int) {

var (
first = 0
last = len(s) - 1
)

for first < last {
s[first], s[last] = s[last], s[first]
first++
last--
}
}

func reverseStrs(s []string) {

var (
first = 0
last = len(s) - 1
)

for first < last {
s[first], s[last] = s[last], s[first]
first++
last--
}
}

func SliceReverse() error {

var (
ints = []int{
1, 2, 3, 4, 5,
}

strs = []string{
"hello", "world",
}

f = func(i []int, s []string) {
fmt.Printf("[original]\tints[%v]\tstrs[%v]\n", ints, strs)
}
)

f(ints, strs)

reverseInts(ints)
reverseStrs(strs)

f(ints, strs)

return nil
}
1 change: 1 addition & 0 deletions lib/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (m SampleMapping) MakeMapping() {
m["slice03"] = slice_.Slice03
m["slice04"] = slice_.Slice04
m["slice05"] = slice_.Slice05
m["slice_reverse"] = slice_.SliceReverse
m["comment01"] = comments.Comment01
m["closure01"] = closure.Closure01
m["string01"] = string_.String01
Expand Down