← All Exercises
Select Records Past Their Retention Window
basicjavascript
Background
Retention rules differ by record category, and a missed deletion is a compliance finding. Computing the eligible set as a pure function keeps the deletion plan reviewable.
Problem
Apply per-category retention periods to a batch of records and return the ids that must be deleted, sorted for a deterministic deletion plan.
Input
JSON object: { records: [{ id, category, ageDays }], policy: { [category]: days, default: days } }Output
JSON array of record ids to delete, sorted
Sample tests
Sample 1
Input: {"records":[{"id":"r1","category":"audit","ageDays":800},{"id":"r2","category":"audit","ageDays":100},{"id":"r3","category":"marketing","ageDays":40}],"policy":{"audit":365,"marketing":30,"default":90}}Expected: ["r1","r3"]
Sample 2
Input: {"records":[{"id":"r4","category":"unknown","ageDays":120}],"policy":{"audit":365,"default":90}}Expected: ["r4"]
Your solution
Learning objective
Apply retention schedules deterministically and produce an auditable deletion list.