Powered By GitBook
EXACTLY_ONE
Check if exactly one item in a list matches

Description

Checks if there is exactly one item in the given list that matches the given criteria. Returns true if one match was found, otherwise false.
The criteria is defined as a formula at the second parameter. The formula is evaluated with each item in the list. The formula must result in a true/false value. When the formula results in true exactly once, then the function will also return true.

Function signature

1
EXACTLY_ONE(list: Array, selectionformula: Function) => Boolean
Copied!
Parameter
Description
List
List of items to search
Selection formula
Formula used to determine if an item matches the criteria

Examples

1
animals = [
2
{
3
"name": "dog",
4
"weight": 123
5
},
6
{
7
"name": "cat",
8
"weight": 48
9
},
10
{
11
"name": "rat",
12
"weight": 10
13
},
14
{
15
"name": "pig",
16
"weight": 230
17
}
18
]
19
products = [
20
{
21
"name": "Duct tape",
22
"category": "Utility"
23
},
24
{
25
"name": "Swiss army knife",
26
"category": "Tools"
27
},
28
{
29
"name": "Glue",
30
"category": "Utility"
31
}
32
]
Copied!
Formula
Return value
EXACTLY_ONE(animals, item.name == "cat")
true
EXACTLY_ONE(animals, item.name == "horse")
false
EXACTLY_ONE(animals, item.weight > 100)
false
EXACTLY_ONE<product>(products, product.category == "Utility")
false
EXACTLY_ONE<product, position>(products, position == 1)
true
Last modified 10mo ago
Export as PDF
Copy link