Counts the number of elements in an array that satisfy the given predicate function.
统计数组中满足给定谓词函数的元素数量。
The type of elements in the array. 数组中元素的类型
The array to count elements in. 要统计元素数量的数组
The function to test each element. 用于测试每个元素的函数
The number of elements that satisfy the predicate. 满足谓词的元素数量
O(n) time complexity - single pass through the array
O(n) 时间复杂度 - 单次遍历数组
count([1, 2, 3, 4, 5], n => n > 2)// => 3 Copy
count([1, 2, 3, 4, 5], n => n > 2)// => 3
count(['a', 'bb', 'ccc'], s => s.length > 1)// => 2 Copy
count(['a', 'bb', 'ccc'], s => s.length > 1)// => 2
Counts the number of elements in an array that satisfy the given predicate function.
统计数组中满足给定谓词函数的元素数量。