Skip to content

Instantly share code, notes, and snippets.

@Imater
Created August 25, 2014 15:36
Show Gist options
  • Save Imater/2148c9ab8c639b89f446 to your computer and use it in GitHub Desktop.
Save Imater/2148c9ab8c639b89f446 to your computer and use it in GitHub Desktop.
varadic set argument
package main
import "fmt"
func add(a ...int) int {
sum := 0
for _, num := range a {
sum += num
}
return sum
}
func main() {
nums := []int{2,3,4,5,6}
fmt.Println(add(nums...))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment