update error of describe. (#445)

This commit is contained in:
aong
2018-03-29 21:38:45 +08:00
committed by jc
parent 2fdd66ac47
commit af797a594f
2 changed files with 18 additions and 18 deletions

View File

@@ -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)

View File

@@ -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
*/