Count the number of elements in an iterable You may optionally provide a predicate function to filter which elements are counted.
Time complexity: O(n)
Space complexity: O(1)
The iterable to count the elements of
Optional
The number of elements in iterable. If predicate was provided, the number of elements in iterable that satisfy predicate.
iterable
predicate
count([1, 2, 3]); // 3 Copy
count([1, 2, 3]); // 3
count([1, 2, 3], number => number % 2 === 1); // 2 Copy
count([1, 2, 3], number => number % 2 === 1); // 2
frequencyTable to count the occurrences of all elements in an iterable
Iterable
Count the number of elements in an iterable You may optionally provide a predicate function to filter which elements are counted.
Time complexity: O(n)
Space complexity: O(1)