Dedupe models and group them by family
A model inventory with repeated entries: keep the latest of each one and count how many there are per family.
RECORDS is a download inventory shaped { name, family, date, digest }. The same name appears several times.
1. Write dedupeLatest(records): return a new array with one record per name, the one with the latest date, sorted by name ascending. Do not modify the input array.
2. Write countByFamily(records): return an object { family: count }.
Dates use the YYYY-MM-DD format, so they compare correctly as strings.
Challenges 0/5
- Keeps one record per model, sorted by name
- Keeps the most recent entry
- Does not modify the input array
- Counts per family after deduping
- An empty inventory gives [] and {}
function dedupeLatest(records) {
// keep one record per name: the one with the latest date
// then sort by name
return records.slice();
}
function countByFamily(records) {
// { family: count }
return {};
}
console.log(countByFamily(dedupeLatest(RECORDS)));Console output appears here (console.log).
Go deeper: the MDN reference →
This in production, with your data? Let's talk for 15 minutes →