Problems › JavaScript › production
How busy was the line
A shift board shows what share of the planned time the line was actually running.
- A whole-number percentage, rounded half up.
- Running longer than planned still reads as 100 — the board does not show more than full.
- No planned time means no percentage: return 0.
utilisationPercent(runMinutes: int, plannedMinutes: int) → int
Where you start
function utilisationPercent(runMinutes, plannedMinutes) {
}
Worked examples
| Call | Result |
|---|---|
utilisationPercent(420, 480) | 88 |
utilisationPercent(480, 480) | 100 |
utilisationPercent(500, 480) | 100 |
utilisationPercent(0, 480) | 0 |
Hint
Round first, then cap. Capping first hides the rounding.
Reference solution in JavaScript
function utilisationPercent(runMinutes, plannedMinutes) {
if (plannedMinutes <= 0 || runMinutes <= 0) return 0;
const pct = Math.floor((runMinutes * 100 + Math.floor(plannedMinutes / 2)) / plannedMinutes);
return Math.min(100, pct);
}