Logo

Programming-Idioms

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

Idiom #316 Count occurrences in a list

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

  c := 0;
  for el in x do if p(el) then Inc(c);
  
c=count(p(x))

p has to be an elemental function with an argument of the type of x.

New implementation...