Counts the number of elements in an iterable that satisfy an optional predicate function. If no predicate is provided, it counts all elements.
Type of elements in the iterable
Optional function to test each element, defaults to counting all elements
A function that takes an iterable and returns the count of matching elements
// Count all elementsconst total = count()([1, 2, 3, 4, 5])// Result: 5 Copy
// Count all elementsconst total = count()([1, 2, 3, 4, 5])// Result: 5
// Count even numbersconst evenCount = count((n: number) => n % 2 === 0)([1, 2, 3, 4, 5])// Result: 2 Copy
// Count even numbersconst evenCount = count((n: number) => n % 2 === 0)([1, 2, 3, 4, 5])// Result: 2
// Count elements at odd indicesconst oddIndices = count((_, index) => index % 2 === 1)([1, 2, 3, 4, 5])// Result: 2 Copy
// Count elements at odd indicesconst oddIndices = count((_, index) => index % 2 === 1)([1, 2, 3, 4, 5])// Result: 2
Counts the number of elements in an iterable that satisfy an optional predicate function. If no predicate is provided, it counts all elements.