At-least quantifier
Learn how to check that at least a certain number of items satisfy a condition.
This quantifier checks whether at least a given number of elements in a collection satisfies a given condition.
Syntax
This quantifier has the following syntax:
at least /*<number>*/ of any /*<item>*/ in /*<collection>*/ satisfies /*<condition>*/
Either satisfy or satisfies can be used interchangeably:
at least /*<number>*/ of any /*<item>*/ in /*<collection>*/ satisfy /*<condition>*/
You can specify whether you want to consider only distinct elements:
at least /*<number>*/ of any distinct /*<item>*/ in /*<collection>*/ satisfies /*<condition>*/
You can also specify a name to refer to the index of the element in the collection:
at least /*<number>*/ of any /*<item>*/ in /*<collection>*/ indexed by /*<index>*/ satisfies /*<condition>*/
You must replace the /*<item>*/ and /*<index>*/ placeholders with a valid identifier. These variables will refer to the element and its index in the collection, as exemplified in the following section.
Examples
Here is an example that checks if at least two numbers in a collection are even:
at least 2 of any number in [2, 4, 6] satisfies number mod 2 is 0 // true
The following example checks whether the user added at least two Apple products after adding the first item to the cart:
at least 2 of any item in cart indexed by index satisfies item's brand is "Apple" and index >= 1
Lastly, this example checks if a user has at least two distinct products of the category "Electronics" in their cart:
at least 2 of any distinct item in cart satisfies item's category is "Electronics"