NaN sorts unpredictably
Review this Java that sorts search results by a computed relevance score (descending) before paginating.
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 20 min
Mark a line and say what kind of problem it is.0 findings
1List<Result> ranked(List<Result> results) {
2 results.sort((a, b) -> {
3 double sa = a.score(); // NaN when no signals fired
4 double sb = b.score();
5 if (sa < sb) {
6 return 1; // b ranks higher
7 }
8 if (sa > sb) {
9 return -1; // a ranks higher
10 }
11 return 0;
12 });
13 return results.subList(0, Math.min(20, results.size()));
14}
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.