#C4700. Filter and Sort Active Employees
Filter and Sort Active Employees
Filter and Sort Active Employees
You are given a JSON array of employees. Each employee is represented as an object with the following attributes: name (a string), employee_id (an integer), and is_active (a boolean). Your task is to filter out the inactive employees (i.e. those with is_active
equal to false) and then sort the remaining active employees in ascending order by their employee_id
. The final list should be output as a JSON array.
The sorting criteria can be represented as follows: $$\text{Sort by } employee\_id \text{ in ascending order.}$$
inputFormat
The input is provided through standard input (stdin) as a single line containing a JSON array. Each element in the array is an object representing an employee with the properties:
name
: stringemployee_id
: integeris_active
: boolean
outputFormat
Output a JSON array (on stdout) of the active employees sorted by their employee_id
in ascending order. The result should be printed in one line.
[{"name": "John Doe", "employee_id": 3, "is_active": false}, {"name": "Jane Smith", "employee_id": 1, "is_active": true}, {"name": "Alice Brown", "employee_id": 2, "is_active": true}]
[{"name":"Jane Smith","employee_id":1,"is_active":true},{"name":"Alice Brown","employee_id":2,"is_active":true}]