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

    Function atMost

    • Determines whether source contains no more than 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

        Maximum number of matching elements allowed. 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 the number of matching elements does not exceed count; otherwise, false.

      Thrown when count is negative.

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

      Enumeration stops as soon as the count is exceeded, making it efficient for large or infinite iterables.

      const numbers = [1, 2, 3, 4, 5];
      const hasAtMostOneEven = atMost(numbers, 1, n => n % 2 === 0);
      console.log(hasAtMostOneEven); // false