3/5

reject(): apply an odd-even driving rule

Medium

To cut traffic, a city runs an odd-even rule: on odd-numbered dates only cars with an odd registration number may drive, and on even-numbered dates only even ones.

Given the registration numbers of a company's pool cars and today's date of the month, return the cars that may drive today, in their original order.

Watch out

  • A number ending in 0 counts as even.
  • reject() removes what matches the test, so the test has to name the cars that must stay off the road.

Inputs

  • ri!plates — List of Integer, the number part of each registration
  • ri!date — Integer, the day of the month

ri! Rule Inputs

ri!platesList of Integer
{
  1234,
  5677,
  2020,
  9
}
ri!dateInteger
12

Example 1 — An even date

Input: ri!plates
{
  1234,
  5677,
  2020,
  9
}
Input: ri!date
12
Output:
{
  1234,
  2020
}

Example 2 — An odd date

Input: ri!plates
{
  1234,
  5677,
  2020,
  9
}
Input: ri!date
7
Output:
{
  5677,
  9
}

Example 3 — A plate ending in 0 on an even date

Input: ri!plates
{
  3050,
  11
}
Input: ri!date
30
Output:
{3050}

Example 4 — Nobody may drive

Input: ri!plates
{
  1,
  3
}
Input: ri!date
2
Output:
{}

Example 5 — No cars

Input: ri!plates
{}
Input: ri!date
5
Output:
{}

Appian Expression Tips

  • • Use ri!variableName for 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