summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-10-26 16:59:05 -0600
committermo khan <mo.khan@gmail.com>2019-10-26 16:59:05 -0600
commitb51279e2f78e542dd78410f4fcc4b9c2b0250455 (patch)
tree478b1ce06607633f5024a1754341fd1c6155e3c3
parent9e4635752b3b1480a7b7bdeec2be2ad647441080 (diff)
Add SumAll
-rw-r--r--sum.go9
-rw-r--r--sum_test.go10
2 files changed, 19 insertions, 0 deletions
diff --git a/sum.go b/sum.go
index 0f46e8d..ad5e29d 100644
--- a/sum.go
+++ b/sum.go
@@ -7,3 +7,12 @@ func Sum(numbers []int) int {
}
return sum
}
+
+func SumAll(numbers ...[]int) []int {
+ var sums []int
+
+ for _, numbers := range numbers {
+ sums = append(sums, Sum(numbers))
+ }
+ return sums
+}
diff --git a/sum_test.go b/sum_test.go
index 3923bfd..4f2b307 100644
--- a/sum_test.go
+++ b/sum_test.go
@@ -1,5 +1,6 @@
package main
+import "reflect"
import "testing"
func TestSum(test *testing.T) {
@@ -23,3 +24,12 @@ func TestSum(test *testing.T) {
}
})
}
+
+func TestSumAll(t *testing.T) {
+ got := SumAll([]int{1, 2}, []int{0, 9})
+ want := []int{3, 9}
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("got %v want %v", got, want)
+ }
+}