Drill

ProblemsTypeScript › machines

Defects per thousand parts

easymachinesTypeScript

Quality control reports scrapped parts as so many per thousand produced, truncated down.

defectsPerThousand(defects: int, produced: int) → int

Solve it in the editor →

Where you start

function defectsPerThousand(defects: number, produced: number): number {
  
}

Worked examples

CallResult
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);
}

The same problem in another language

More machines problems in TypeScript