Problems › JavaScript › production
Defects per million parts
Quality reports the defect rate in parts per million, because "0.03%" is harder to compare across lines than "300 ppm".
- Rounded to the nearest whole ppm, halves going up.
- A run that produced nothing has no rate: return 0.
defectPpm(defects: int, produced: int) → int
Where you start
function defectPpm(defects, produced) {
}
Worked examples
| Call | Result |
|---|---|
defectPpm(3, 10000) | 300 |
defectPpm(0, 10000) | 0 |
defectPpm(1, 3) | 333333 |
defectPpm(2, 3) | 666667 |
Hint
defects * 1000000 / produced, with half the divisor added before dividing so it rounds instead of truncating.
Reference solution in JavaScript
function defectPpm(defects, produced) {
if (produced <= 0) return 0;
return Math.floor((defects * 1000000 + Math.floor(produced / 2)) / produced);
}