Drill

ProblemsJavaScript › machines

Is maintenance due yet

easymachinesJavaScript

A machine logs the day of its last service and a service interval in days. A checker decides whether today it is time to service it again.

maintenanceDue(lastService: int, intervalDays: int, today: int) → bool

Solve it in the editor →

Where you start

function maintenanceDue(lastService, intervalDays, today) {
  
}

Worked examples

CallResult
maintenanceDue(100, 10, 110)true
maintenanceDue(100, 10, 109)false
maintenanceDue(100, 10, 100)false
maintenanceDue(100, 0, 50)true

Hint

Guard the two odd cases first, then compare the gap against the interval.

Reference solution in JavaScript
function maintenanceDue(lastService, intervalDays, today) {
  if (intervalDays <= 0) return true;
  if (today < lastService) return false;
  return today - lastService >= intervalDays;
}

The same problem in another language

More machines problems in JavaScript