Solution Review: Variable Number of Arguments
This lesson discusses the solution to the challenge given in the previous lesson.
We'll cover the following...
We'll cover the following...
Go (1.6.2)
package mainimport "fmt"func main() {// function calls for multiple arg.fmt.Println(sumInts())fmt.Println(sumInts(2, 3))fmt.Println(sumInts(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))}func sumInts(list ...int) (sum int){ // function to calculate sum of variable arg.for _, v := range list {sum = sum+v}return}
In the code above, at line 11 there is a function header: sumInts(list ...int)(sum int)
which means that sumInts
takes ...