Problems › TypeScript › logistics
When does the order actually arrive
Fulfilment ships on business days only — Saturday and Sunday never move a parcel. Estimate the calendar day an order placed on day 0 reaches the door after processingDays of travel.
- Day 0 is a Monday, and the parcel sets off the next business day.
- One business day (Mon–Fri) is consumed per day of travel; weekends do not count.
- Return the calendar day, counted from day 0, on which the last travel day ends.
- processingDays of zero still ships on the next business day.
deliveryEta(processingDays: int) → int
Where you start
function deliveryEta(processingDays: number): number {
}
Worked examples
| Call | Result |
|---|---|
deliveryEta(1) | 1 |
deliveryEta(2) | 2 |
deliveryEta(5) | 7 |
deliveryEta(6) | 8 |
Hint
Walk day by day; each business day consumed advances the done count, and only stop once it matches processingDays.
Reference solution in TypeScript
function deliveryEta(processingDays: number): number {
let day = 1;
let done = 0;
while (done < processingDays) {
if (day % 7 < 5) done++;
if (done < processingDays) day++;
}
return day;
}