fix: coding style and file format for chapter 7.

This commit is contained in:
Bo-Yi Wu
2017-02-11 12:26:05 +08:00
parent d9041c7fc3
commit e6d601d3a1
15 changed files with 375 additions and 375 deletions

View File

@@ -1,19 +1,19 @@
// remove_slice.go
package main
import (
"fmt"
)
func main() {
s := []string{"M", "N", "O", "P", "Q", "R"}
res := RemoveStringSlice(s, 2, 4)
fmt.Println(res) // [M N Q R]
}
func RemoveStringSlice(slice []string, start, end int) []string {
result := make([]string, len(slice) - (end - start))
at := copy(result, slice[:start])
copy(result[at:], slice[end:])
return result
}
// remove_slice.go
package main
import (
"fmt"
)
func main() {
s := []string{"M", "N", "O", "P", "Q", "R"}
res := RemoveStringSlice(s, 2, 4)
fmt.Println(res) // [M N Q R]
}
func RemoveStringSlice(slice []string, start, end int) []string {
result := make([]string, len(slice)-(end-start))
at := copy(result, slice[:start])
copy(result[at:], slice[end:])
return result
}