Skip to content

Commit 0ac09ff

Browse files
committed
♻️ (sum_tail): refactor sum_tail func
1 parent dcc47a3 commit 0ac09ff

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arrays-and-slices/sum.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ func SumAll(numbersToSum ...[]int) []int {
1818
}
1919

2020
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)
21+
var sums []int
22+
for _, numbers := range numbersToSum {
23+
tail := numbers[1:]
24+
sums = append(sums, Sum(tail))
2525
}
2626
return sums
2727
}

0 commit comments

Comments
 (0)