16 lines
294 B
Go
16 lines
294 B
Go
|
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
|
||
|
}
|