go-by-test/sum/sum.go

21 lines
287 B
Go
Raw Normal View History

2024-09-10 19:15:12 +00:00
package sum
2024-09-10 19:27:13 +00:00
func Sum(numbers []int) int {
2024-09-10 19:15:12 +00:00
sum := 0
2024-09-10 19:16:01 +00:00
for _, number := range numbers {
sum += number
2024-09-10 19:15:12 +00:00
}
return sum
}
2024-09-10 19:34:27 +00:00
2024-09-10 19:38:18 +00:00
func SumAll(numbersToSum ...[]int) []int {
res := make([]int, len(numbersToSum))
for i, numbers := range numbersToSum {
res[i] = Sum(numbers)
}
return res
2024-09-10 19:34:27 +00:00
}