a!localVariables(): write a basket summary with free delivery
Hard
A checkout page sums up the basket in one line and says how far the shopper is from free delivery, which starts at a total of $50:
- under $50 —
"3 items, total $22, add $28 for free delivery" - $50 or more —
"2 items, total $55, free delivery" - a single item reads
"1 item", not"1 items" - nothing in the basket —
"Basket is empty"
The count and the total each appear in more than one place. Work each out once and name it.
Input
ri!prices— List of Integer
ri! Rule Inputs
ri!pricesList of Integer{
10,
5,
7
}Example 1 — Short of free delivery
Input: ri!prices
{
10,
5,
7
}Output:
"3 items, total $22, add $28 for free delivery"
Example 2 — Free delivery reached
Input: ri!prices
{
30,
25
}Output:
"2 items, total $55, free delivery"
Example 3 — Exactly $50 qualifies
Input: ri!prices
{50}Output:
"1 item, total $50, free delivery"
Example 4 — A single cheap item
Input: ri!prices
{4}Output:
"1 item, total $4, add $46 for free delivery"
Example 5 — An empty basket
Input: ri!prices
{}Output:
"Basket is empty"
Appian Expression Tips
- • Use
ri!variableNamefor rule inputs - • Use
a!localVariables(local!x: …, body)for locals - • Use
a!forEach(items: …, expression: fv!item)to iterate - • Use
where()/reject(fn!isnull, list)to filter