Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shockalotti/8d42841ee71f1e204fff to your computer and use it in GitHub Desktop.
Save shockalotti/8d42841ee71f1e204fff to your computer and use it in GitHub Desktop.
Go Golang - pass a variable slice of ints to function
package main
import "fmt"
func add(args ...int) int {
total :=0
for _, v := range args {
total += v
}
return total
}
func main() {
xs := []int{1,2,3}
fmt.Println(add(xs...))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment