-
Notifications
You must be signed in to change notification settings - Fork 0
Count
The listutils:count
function checks how many times an element occurs in a list.
Input is given using the listutils:in
storage:
Field | Meaning |
---|---|
List |
The list that could contain the element. |
Data |
The element that could occur in the list. |
After defining the input, run the function listutils:count
.
Various comparison functions can be used to match elements. For more about comparison functions, see the Comparison Functions page.
Errors that display when executing the listutils:count
function as a player in debug mode.
Error | Message |
---|---|
TBD | TBD |
The success of the operation is stored in the $listutils.success listutils.out
score. This score is 1
on success and 0
otherwise. Success will be 0
when the list does not contain the element.
The result of the operation is stored in the $listutils.result listutils.out
score. The result is equal to the amount of times the element occurred in the list.
Take the example list ExampleList: ["foo", "Hello World!", "foo", "bar"]
in the listutils:examples
storage. We want to find out how many times it contains "foo"
:
# Add List to the input.
data modify storage listutils:in List set from storage listutils:examples ExampleList
# Add Data to the input.
data modify storage listutils:in Data set value "foo"
# Call the function.
function listutils:count
This will return a result of 2
in the $listutils.result listutils.out
score, since the list contains the string "foo"
two times.