Your question is ES6 Rewrite a 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.
Apex Systems Candidate Hub stores a chronological stream of candidate status events. Rewrite the legacy status-summary logic using modern ES6-style collection and transformation techniques. Given the events, determine each candidate's final status, then count final statuses by recruiting team.
Implement the equivalent algorithm in the required function signature. Each event has a candidate ID, team, status, and integer timestamp. A candidate may appear in multiple events, but timestamps for the same candidate are unique.
Input is an array of objects with fields candidateId, team, status, and timestamp. Return an object whose keys are team names. Each team maps to an object containing status names and the number of candidates whose latest event has that status. Include only teams and statuses present in the input. The order of object keys does not matter.
Example 1:
Input: events = [{candidateId: "c1", team: "Cloud", status: "screen", timestamp: 2}, {candidateId: "c1", team: "Cloud", status: "interview", timestamp: 5}, {candidateId: "c2", team: "Cloud", status: "screen", timestamp: 3}]
Output: {"Cloud": {"interview": 1, "screen": 1}}
c1 ends in interview, while c2 remains in screen.
Example 2:
Input: events = [{candidateId: "c7", team: "Security", status: "rejected", timestamp: 4}, {candidateId: "c8", team: "Cloud", status: "offer", timestamp: 1}]
Output: {"Security": {"rejected": 1}, "Cloud": {"offer": 1}}
def summarize_candidate_status(events):