normalize printing
This commit is contained in:
parent
22f6542915
commit
f79d9e151f
@ -9,25 +9,25 @@ import "fmt"
|
|||||||
|
|
||||||
// Here's a function that will take an arbitrary number
|
// Here's a function that will take an arbitrary number
|
||||||
// of `ints` as arguments.
|
// of `ints` as arguments.
|
||||||
func sum(nums ...int) int {
|
func sum(nums ...int) {
|
||||||
fmt.Print(nums, " ")
|
fmt.Print(nums, " ")
|
||||||
total := 0
|
total := 0
|
||||||
for _, num := range nums {
|
for _, num := range nums {
|
||||||
total += num
|
total += num
|
||||||
}
|
}
|
||||||
return total
|
fmt.Println(total)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Variadic functions can be called in the usual way
|
// Variadic functions can be called in the usual way
|
||||||
// with individual arguments.
|
// with individual arguments.
|
||||||
fmt.Println(sum(1, 2))
|
sum(1, 2)
|
||||||
fmt.Println(sum(1, 2, 3))
|
sum(1, 2, 3)
|
||||||
|
|
||||||
// If you already have multiple args in a slice,
|
// If you already have multiple args in a slice,
|
||||||
// apply them to a variadic function using
|
// apply them to a variadic function using
|
||||||
// `func(slice...)` like this.
|
// `func(slice...)` like this.
|
||||||
nums := []int{1, 2, 3, 4}
|
nums := []int{1, 2, 3, 4}
|
||||||
fmt.Println(sum(nums...))
|
sum(nums...)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user