Problems › JavaScript › network
Cache hit ratio in permille
A proxy dashboard reports cache efficiency as permille — parts per thousand — so operators can spot a 2 permille dip that a percentage would round away.
- Return floor(hits × 1000 / requests).
- When requests is zero or negative, return 0.
cacheHitPermille(hits: int, requests: int) → int
Where you start
function cacheHitPermille(hits, requests) {
}
Worked examples
| Call | Result |
|---|---|
cacheHitPermille(500, 1000) | 500 |
cacheHitPermille(1, 3) | 333 |
cacheHitPermille(0, 100) | 0 |
cacheHitPermille(100, 0) | 0 |
Hint
Integer division gives the floor you need.
Reference solution in JavaScript
function cacheHitPermille(hits, requests) {
if (requests <= 0) return 0;
return Math.floor(hits * 1000 / requests);
}