Problems › TypeScript › network
Which HTTP status family does a code belong to
HTTP status codes are grouped by their hundreds digit: 2xx means success, 5xx means server trouble, and so on.
- 100-199 return 1, 200-299 return 2, 300-399 return 3, 400-499 return 4, 500-599 return 5.
- Any value outside those ranges, including negatives, returns 0.
httpFamily(status: int) → int
Where you start
function httpFamily(status: number): number {
}
Worked examples
| Call | Result |
|---|---|
httpFamily(200) | 2 |
httpFamily(404) | 4 |
httpFamily(503) | 5 |
httpFamily(100) | 1 |
Hint
Divide by 100 and check the result.
Reference solution in TypeScript
function httpFamily(status: number): number {
if (status >= 100 && status <= 199) return 1;
if (status >= 200 && status <= 299) return 2;
if (status >= 300 && status <= 399) return 3;
if (status >= 400 && status <= 499) return 4;
if (status >= 500 && status <= 599) return 5;
return 0;
}