Created
May 27, 2014 08:12
-
-
Save shockalotti/8d42841ee71f1e204fff to your computer and use it in GitHub Desktop.
Go Golang - pass a variable slice of ints to function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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