Problems › TypeScript › logistics
How many parcels missed the van
Items boarded the van if their ready time is before backstopMinutes. Count how many missed it, so the leftover list can be quoted again.
- ready times are in minutes past midnight.
- An item ready exactly at the backstop still boards.
lateParcels(readyTimes: list<int>, backstopMinutes: int) → int
Where you start
function lateParcels(readyTimes: number[], backstopMinutes: number): number {
}
Worked examples
| Call | Result |
|---|---|
lateParcels([100,200,300], 250) | 1 |
lateParcels([250,250], 250) | 0 |
lateParcels([300], 100) | 1 |
lateParcels([], 500) | 0 |
Hint
Count the ones that fail the comparison.
Reference solution in TypeScript
function lateParcels(readyTimes: number[], backstopMinutes: number): number {
let n = 0;
for (const t of readyTimes) if (t > backstopMinutes) n++;
return n;
}