The bike-ride demo produced a single total. A parcel desk needs a reusable report of count and kilograms delivered, ignoring parcels that are still in transit.
summaryFor(deliveries) must return { count, totalKg } without changing the input array. Use filter, map, and reduce to compose the calculation. formatSummary(summary) turns that result into one Console-friendly sentence.
This unrelated activity report composes the same filter → map → reduce pattern:
const readings = [{ active: true, minutes: 20 }, { active: false, minutes: 40 }];
const minutes = readings.filter(item => item.active)
.map(item => item.minutes)
.reduce((total, value) => total + value, 0);
console.log(minutes); // 20
summaryFor(deliveries) with filter, map, and reduce (initial sum 0) to count delivered parcels and total their kilograms; empty input yields { count: 0, totalKg: 0 }.formatSummary(summary) to return a sentence using the supplied count and totalKg fields.formatSummary(summaryFor(deliveries)) on its own line.You can now compose callbacks and array transformations into reports. Take the section quiz to review the patterns.
Filter for delivered records; map each weightGrams to kilograms by dividing by 1000.
Reduce from 0 so there is a numeric total even when nothing was delivered.