gotdd/adder.go

34 lines
539 B
Go
Raw Permalink Normal View History

2022-01-20 04:20:12 +00:00
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
}