Filter by a condition
Function: Filter by a condition
This action helps you narrow down a list of items based on specific criteria you define. Imagine you have a long list of customers, products, or tasks, and you only want to see the ones that meet certain conditions, like customers in a specific region or products below a certain price. This action allows you to do just that, creating a new, smaller list containing only the items that match your rules.
Input,
- List to Filter (
LIST, Array of Objects, Required): This is the original list of items you want to sort through. For example, a list of all your products, or all your employees. - Condition (
CONDITION, String, Required): This is the rule that each item in your list must follow to be included in the new, filtered list. You'll write this as a simple expression, likeitem.price < 50to find products cheaper than 50, oritem.status == "Active"to find active users. - Attribute to Filter By (
LIST_OBJECT_ATTRIBUTE, String, Optional): If your condition is very simple and only checks one specific part of each item (likepriceorstatus), you can optionally specify that attribute here. However, it's often easier to include the attribute directly in yourCondition(e.g.,item.price).
Output,
- Result (
RESULT, Number): A number representing the list that has been filtered based on your condition. This number could be a count of the items that met the condition, or a reference to the newly created filtered list.
Execution Flow,
Real-Life Examples,
-
Finding Overdue Tasks
- Inputs:
List to Filter: A list of all tasks in your project management system.Condition:item.dueDate < today\(\)(assumingtoday\(\)is a function that returns the current date)Attribute to Filter By: (Leave blank, as the condition directly usesitem.dueDate)
- Result: A number, for example,
5, indicating that 5 tasks are overdue.
- Inputs:
-
Identifying High-Value Customers
- Inputs:
List to Filter: A list of all your customers.Condition:item.totalPurchases > 1000Attribute to Filter By: (Leave blank)
- Result: A number, for example,
15, representing the 15 customers who have made over $1000 in purchases.
- Inputs:
-
Filtering Available Products by Stock Level
- Inputs:
List to Filter: A list of all products in your inventory.Condition:item.stockQuantity > 0Attribute to Filter By: (Leave blank)
- Result: A number, for example,
120, indicating that 120 products currently have stock available.
- Inputs: