@mirei/ts-collections
    Preparing search index...

    Function exactly

    • Determines whether source contains exactly count elements that satisfy the optional predicate.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The iterable whose elements are evaluated.

      • count: number

        Exact number of matching elements required. Must be greater than or equal to 0.

      • Optionalpredicate: Predicate<TElement>

        Optional predicate that determines which elements are counted. When omitted, every element is considered a match.

      Returns boolean

      true when exactly count matching elements are present; otherwise, false.

      Thrown when count is negative.

      Re-throws any error encountered while iterating source or executing the predicate.

      Enumeration stops once the running total exceeds count, preventing unnecessary work on long iterables.

      const numbers = [1, 2, 3, 4, 5];
      const hasExactlyThreeOdds = exactly(numbers, 3, n => n % 2 !== 0);
      console.log(hasExactlyThreeOdds); // true