Drill

ProblemsJavaScript › logistics

When does the order actually arrive

mediumlogisticsJavaScript

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.

deliveryEta(processingDays: int) → int

Solve it in the editor →

Where you start

function deliveryEta(processingDays) {
  
}

Worked examples

CallResult
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 JavaScript
function deliveryEta(processingDays) {
  let day = 1, done = 0;
  while (done < processingDays) {
    if (day % 7 < 5) done++;
    if (done < processingDays) day++;
  }
  return day;
}

The same problem in another language

More logistics problems in JavaScript