Hit rate rounds to zero
Review this Go that computes per-cache hit-rate percentages for a dashboard tile.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 16 min
Mark a line and say what kind of problem it is.0 findings
1type CacheStats struct {
2 Name string
3 Hits int
4 Total int
5}
6
7func hitRate(hits, total int) int {
8 if total == 0 {
9 return 0
10 }
11 return (hits / total) * 100
12}
13
14func tiles(stats []CacheStats) map[string]int {
15 out := map[string]int{}
16 for _, s := range stats {
17 out[s.Name] = hitRate(s.Hits, s.Total) // e.g. 950/1000
18 }
19 return out
20}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.