Skip to content

Commit dcc47a3

Browse files
committed
✨ (sum_tails): add sum_tails function
1 parent a722b14 commit dcc47a3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

arrays-and-slices/sum.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ func SumAll(numbersToSum ...[]int) []int {
1616
}
1717
return sums
1818
}
19+
20+
func SumAllTails(numbersToSum ...[]int) []int {
21+
lengthOfNumbersToSum := len(numbersToSum)
22+
sums := make([]int, lengthOfNumbersToSum)
23+
for i, numbers := range numbersToSum {
24+
sums[i] = Sum(numbers)
25+
}
26+
return sums
27+
}

arrays-and-slices/sum_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestSumAll(t *testing.T) {
4141

4242
func TestSumAllTails(t *testing.T) {
4343

44-
got := SumAllTails([]int{1, 2}, int{0, 9})
44+
got := SumAllTails([]int{1, 2}, []int{0, 9})
4545
want := []int{2, 9}
4646

4747
if !reflect.DeepEqual(got, want) {

0 commit comments

Comments
 (0)