Loading homepage
Implement dataSelection(rows, requirement), a small filtering engine for an array of records. A requirement can test a field or combine other requirements with nested AND, OR, and NOT groups.
Use { all: [...] } for AND, { any: [...] } for OR, and { not: requirement } for negation. A field rule has { field, operator, value }. For example, a dashboard could select active developers whose experience is at least two years.
Input: const rows = [{ id: 1, active: true, profile: { years: 3 } }, { id: 2, active: false, profile: { years: 5 } }]; dataSelection(rows, { all: [ { field: "active", operator: "eq", value: true }, { field: "profile.years", operator: "gte", value: 2 }, ] }); Output: [{ id: 1, active: true, profile: { years: 3 } }]
Input: dataSelection([{ id: 1 }, { id: 2, note: undefined }], { field: "note", operator: "exists", value: false }); Output: [{ id: 1 }]
Input: dataSelection([{ id: 1 }], { any: [] }); Output: []
Use the same documented API in both language variants.