Count and CountCmp added
This commit is contained in:
parent
cdb1cf3e03
commit
84cc7a9e05
15
count.go
Normal file
15
count.go
Normal file
@ -0,0 +1,15 @@
|
||||
package slices
|
||||
|
||||
func Count[T comparable](slice []T, value T) int {
|
||||
return CountCmp(slice, value, DefaultEqualityComparator[T])
|
||||
}
|
||||
|
||||
func CountCmp[T comparable](slice []T, value T, cmp EqualityComparator[T]) int {
|
||||
c := 0
|
||||
for _, v := range slice {
|
||||
if cmp(v, value) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
Loading…
Reference in New Issue
Block a user