Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: unknwon/the-way-to-go_ZH_CN
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: orz2333/the-way-to-go_ZH_CN
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Mar 28, 2018

  1. update error of describe.

    yxwzaxns committed Mar 28, 2018
    Copy the full SHA
    c578318 View commit details
Showing with 18 additions and 18 deletions.
  1. +10 −10 eBook/06.3.md
  2. +8 −8 eBook/examples/chapter_6/varnumpar.go
20 changes: 10 additions & 10 deletions eBook/06.3.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ Greeting("hello:", "Joe", "Anna", "Eileen")

在 Greeting 函数中,变量 `who` 的值为 `[]string{"Joe", "Anna", "Eileen"}`
如果参数被存储在一个数组 `arr` 中,则可以通过 `arr...` 的形式来传递参数调用变参函数。
如果参数被存储在一个 slice 类型的变量 `slice` 中,则可以通过 `slice...` 的形式来传递参数调用变参函数。
示例 6.7 [varnumpar.go](examples/chapter_6/varnumpar.go)
@@ -29,17 +29,17 @@ import "fmt"
func main() {
x := min(1, 3, 2, 0)
fmt.Printf("The minimum is: %d\n", x)
arr := []int{7,9,3,5,1}
x = min(arr...)
fmt.Printf("The minimum in the array arr is: %d", x)
slice := []int{7,9,3,5,1}
x = min(slice...)
fmt.Printf("The minimum in the slice is: %d", x)
}

func min(a ...int) int {
if len(a)==0 {
func min(s ...int) int {
if len(s)==0 {
return 0
}
min := a[0]
for _, v := range a {
min := s[0]
for _, v := range s {
if v < min {
min = v
}
@@ -51,7 +51,7 @@ func min(a ...int) int {
输出:

The minimum is: 0
The minimum in the array arr is: 1
The minimum in the slice is: 1

**练习 6.3** varargs.go

@@ -109,4 +109,4 @@ func F3(s []string) { }

- [目录](directory.md)
- 上一节:[函数参数与返回值](06.2.md)
- 下一节:[defer 和追踪](06.4.md)
- 下一节:[defer 和追踪](06.4.md)
16 changes: 8 additions & 8 deletions eBook/examples/chapter_6/varnumpar.go
Original file line number Diff line number Diff line change
@@ -5,17 +5,17 @@ import "fmt"
func main() {
x := Min(1, 3, 2, 0)
fmt.Printf("The minimum is: %d\n", x)
arr := []int{7, 9, 3, 5, 1}
x = Min(arr...)
fmt.Printf("The minimum in the array arr is: %d", x)
slice := []int{7, 9, 3, 5, 1}
x = Min(slice...)
fmt.Printf("The minimum in the slice is: %d", x)
}

func Min(a ...int) int {
if len(a) == 0 {
func Min(s ...int) int {
if len(s) == 0 {
return 0
}
min := a[0]
for _, v := range a {
min := s[0]
for _, v := range s {
if v < min {
min = v
}
@@ -25,5 +25,5 @@ func Min(a ...int) int {

/*
The minimum is: 0
The minimum in the array arr is: 1
The minimum in the slice is: 1
*/