Problems › JavaScript › machines
Finished units in a shift
A production planner works out how much good product a shift turns out: run time at a rate, less scrap.
- Run time is the shift minus the breaks, in minutes.
- Units per hour are applied to that run time, truncated down.
- Finally scrap percent leaves only the finished units, again truncated down.
shiftOutput(perHour: int, shiftMinutes: int, breakMinutes: int, scrapPercent: int) → int
Where you start
function shiftOutput(perHour, shiftMinutes, breakMinutes, scrapPercent) {
}
Worked examples
| Call | Result |
|---|---|
shiftOutput(360, 480, 30, 10) | 2430 |
shiftOutput(60, 120, 0, 0) | 120 |
shiftOutput(360, 480, 480, 0) | 0 |
shiftOutput(60, 390, 30, 25) | 270 |
Hint
Do the truncation at each step: first production, then finished.
Reference solution in JavaScript
function shiftOutput(perHour, shiftMinutes, breakMinutes, scrapPercent) {
const production = Math.floor(((shiftMinutes - breakMinutes) * perHour) / 60);
return Math.floor((production * (100 - scrapPercent)) / 100);
}