Skip to content

Commit

Permalink
feat: type/slicesutil: add MatrixIntColSums(), SliceIntSum()
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Mar 10, 2024
1 parent d495a00 commit b56f7f2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions type/slicesutil/int.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package slicesutil

func SliceIntSum(s []int) int {
sum := 0
for _, si := range s {
sum += si
}
return sum
}

func MatrixIntColSums(m [][]int) []int {
sums := []int{}
for _, r := range m {
for ci, c := range r {
for ci >= len(sums) {
sums = append(sums, 0)
}
sums[ci] += c
}
}
return sums
}

0 comments on commit b56f7f2

Please sign in to comment.