Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran

Idiom #316 Count occurrences in a list

Determine the number c of elements in the list x that satisfy the predicate p.

  
c=count(p(x))

p has to be an elemental function with an argument of the type of x.
c := 0
for _, v := range x {
	if p(v) {
		c++
	}
}

New implementation...