Implement a function selectData(rows, predicate) that filters rows of data based on a dynamic predicate.
The function should:
rows) representing a dataset.Examples
const data = [ { id: 1, user: { name: 'Alice', age: 25 } }, { id: 2, user: { name: 'Bob', age: 30 } }, { id: 3, user: { name: 'Charlie', age: 30 } }, ]; // Using a predicate function selectData(data, row => row.user.age === 30); // returns [{ id: 2, ... }, { id: 3, ... }] // Using a conditions object selectData(data, { 'user.age': 30, 'user.name': 'Bob' }); // returns [{ id: 2, user: { name: 'Bob', age: 30 } }]
JavaScript Function
No test results yet
Click "Run" to execute tests