mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:48:29 +08:00
fix: coding style and file format for chapter 7.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user