Drill

ProblemsTypeScript › monitoring

What share of requests failed

easymonitoringTypeScript

A status page shows the error rate as a whole percentage, because nobody reads four decimal places at a glance.

errorRate(errors: int, total: int) → int

Solve it in the editor →

Where you start

function errorRate(errors: number, total: number): number {
  
}

Worked examples

CallResult
errorRate(5, 100)5
errorRate(1, 3)33
errorRate(2, 3)67
errorRate(0, 100)0

Hint

Add half the divisor before dividing, then cap.

Reference solution in TypeScript
function errorRate(errors: number, total: number): number {
  if (total <= 0 || errors <= 0) return 0;
  return Math.min(100, Math.floor((errors * 100 + Math.floor(total / 2)) / total));
}

The same problem in another language

More monitoring problems in TypeScript