Problems › TypeScript › network
Classify a latency measurement
Monitoring dashboards colour-code every request by how long it took. Bucket the latency into a human-readable band.
- Under 250 ms is "fast".
- Under 1000 ms is "normal".
- Under 3000 ms is "slow".
- Anything at or above 3000 ms is "timeout".
latencyBand(latencyMs: int) → string
Where you start
function latencyBand(latencyMs: number): string {
}
Worked examples
| Call | Result |
|---|---|
latencyBand(0) | "fast" |
latencyBand(100) | "fast" |
latencyBand(250) | "normal" |
latencyBand(999) | "normal" |
Hint
Check the thresholds from smallest to largest.
Reference solution in TypeScript
function latencyBand(latencyMs: number): string {
if (latencyMs < 250) return "fast";
if (latencyMs < 1000) return "normal";
if (latencyMs < 3000) return "slow";
return "timeout";
}