Your question is API Data Transformation Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The Justworks People frontend receives employee records in an API-specific shape. Transform the response into department groups that are ready to render, while filtering inactive benefits, removing duplicate plans, and applying deterministic sorting.
Implement transform_justworks_people(response). The input is a dictionary containing a data array. Each employee has id, first_name, last_name, employment_status, an optional department object with id and name, and a benefits array. Each benefit has plan_id, plan_name, and status.
Return a list of dictionaries with this shape:
department_id: the department ID, or null when the employee has no departmentdepartment: the department name, or "Unassigned" when there is no departmentemployees: transformed employee objects containing id, name, status, and active_plansInclude only benefits whose status is "active". Deduplicate benefits by plan_id, retain the first name encountered for each plan, and sort plan names alphabetically. Group employees by department, sort employees by last name, first name, then ID, and sort department groups by department name.
def transform_justworks_people(response):