Drill

ProblemsJavaScript › machines

Machine uptime per thousand

easymachinesJavaScript

Maintenance reports uptime as parts per thousand so a single line reads as 993 instead of a harder-to-compare 99.3%.

uptimePermille(upHours: int, downHours: int) → int

Solve it in the editor →

Where you start

function uptimePermille(upHours, downHours) {
  
}

Worked examples

CallResult
uptimePermille(1000, 0)1000
uptimePermille(993, 7)993
uptimePermille(750, 250)750
uptimePermille(3, 1)750

Hint

upHours * 1000 / total — but a total of zero is a special case that must come first.

Reference solution in JavaScript
function uptimePermille(upHours, downHours) {
  if (upHours + downHours === 0) return 1000;
  return Math.floor((upHours * 1000) / (upHours + downHours));
}

The same problem in another language

More machines problems in JavaScript