A shipping desk records parcel scans as JSON. A parcel scanned twice contributes two scans to its zone, but only one distinct tracking ID. Build a report that keeps those counts separate.
const visits = JSON.parse('[{"room":"East","badge":"B1"},{"room":"East","badge":"B1"}]');
const byRoom = new Map();
const badges = new Set();
for (const visit of visits) {
byRoom.set(visit.room, (byRoom.get(visit.room) ?? 0) + 1);
badges.add(visit.badge);
}
console.log(byRoom.get("East"), badges.size);
Your feed uses zone and tracking instead of room and badge. It is valid JSON containing an array of records with those fields. You do not need to fetch data or handle malformed JSON in this exercise.
Start each collection helper with an empty Map or Set. Then an empty array needs no special branch: the loop runs zero times and the helper returns the empty collection. The report's properties are named byZone and uniqueTracking.
Edit script.js. The first three supplied probes use independent samples. You can finish parsing, counting, or deduplication before the summary helper works. Leave the probes in place. Run to inspect their output, then Submit.
parseScans(jsonText) to parse the JSON text into an array of scan records.countByZone(scans) to return a Map counting every scan by zone; return an empty Map for no scans.uniqueIds(scans) to return a Set of tracking IDs; return an empty Set for no scans.summarizeScans(jsonText) to use the helpers and return { byZone, uniqueTracking }, including for "[]".North: 2 | South: 2 | unique: 3 from summarizeScans(scanFeed) on its own line.You have now turned structured text into a lookup and a distinct-ID count. Take the section quiz before moving on to strings.
Parse jsonText once; then iterate each scan in the resulting array.
Use (byZone.get(scan.zone) ?? 0) + 1 to increment counts.