Problems › TypeScript › machines
Defects per thousand parts
Quality control reports scrapped parts as so many per thousand produced, truncated down.
- The rate is defects per thousand, truncated down.
- A run that produced nothing has no rate: return 0.
defectsPerThousand(defects: int, produced: int) → int
Where you start
function defectsPerThousand(defects: number, produced: number): number {
}
Worked examples
| Call | Result |
|---|---|
defectsPerThousand(500, 1000) | 500 |
defectsPerThousand(3, 10000) | 0 |
defectsPerThousand(1, 3) | 333 |
defectsPerThousand(2, 3) | 666 |
Hint
defects * 1000 / produced, guarding the divide by zero.
Reference solution in TypeScript
function defectsPerThousand(defects: number, produced: number): number {
if (produced <= 0) return 0;
return Math.floor((defects * 1000) / produced);
}