count method

int count([
  1. bool test(
    1. E element
    )?
])

返回满足 test 条件的元素个数。 test 为空,则返回所有数量。

举例:

[1, 2, 3, 13, 14, 15].count();             // 6
[1, 2, 3, 13, 14, 15].count((n) => n > 9); // 3

Implementation

int count([bool Function(E element)? test]) {
  if (isEmpty) return 0;
  if (test == null) return length;
  return where(test).length;
}