Filter
Creates a new list with all items that pass the test of the predicate function.
Description
The filter brick creates a new list that contains all items for which the provided function (predicate) returns true
and so pass the test.
The output control flow is triggered when all items have been processed.
In other words, Filter
selects some elements of a list and is equivalent to Javascript's <a href="https://medium.com/@JeffLombardJr/understanding-foreach-map-filter-and-find-in-javascript-f91da93b9f2c" target="_blank">filter()</a>
Example:
-
inputs
- list =
["spray", "limit", "elite", "exuberant", "destruction", "present"]
- predicate =
(word) => word.length > 6
- list =
-
outputs
- filtered list =
["exuberant", "destruction", "present"]
- filtered list =
Inputs
- Control Flow (Control Flow)
- list (List): The original list to iterate on.
- predicate (Predicate): The predicate function that test whether an item is present in the filtered list.
Inputs:
-start (Control Flow)
: Triggered when the item is to be processed.
-item (Object)
: The current item of the list.
-rank (Number)
: The rank of the current item.
-list (List)
: The full list being iterated.
Outputs:
-end (Control Flow)
: Triggered when the processing is completed.
-result (Boolean)
: Set it totrue
ifitem
is to be selected by the filter and should be kept infiltered list
.
Outputs
- Control Flow (Control Flow)
- filtered list (List): The created list with items that pass the test.