34 lines
539 B
Go
34 lines
539 B
Go
package main
|
|
|
|
//func main() {
|
|
//}
|
|
|
|
func Add(numbers []int) int {
|
|
var sum int
|
|
for _, num := range numbers {
|
|
sum += num
|
|
}
|
|
return sum
|
|
}
|
|
|
|
func SumAll(numbersToSum ...[]int) []int {
|
|
var sums []int
|
|
for _, numbers := range numbersToSum {
|
|
sums = append(sums, Add(numbers))
|
|
}
|
|
return sums
|
|
}
|
|
|
|
func SumAllTails(numbersToSum ...[]int) []int {
|
|
var sums []int
|
|
for _, numbers := range numbersToSum {
|
|
if len(numbers) == 0 {
|
|
sums = append(sums, 0)
|
|
} else {
|
|
tail := numbers[1:]
|
|
sums = append(sums, Add(tail))
|
|
}
|
|
}
|
|
return sums
|
|
}
|