MediumJavaScriptPractice mode: untimed, 3 hints
Top scorer from a CSV
topScorer(rows) returns the name with the highest score, the first one on a tie, or null when there are no rows. The rows come from a CSV export, so every field is a string: { name: "Asha", score: "87" }.
The code has exactly one planted bug. Reproduce it with the tests, fix it with the smallest change, then submit.
Visible tests
nine against ten
- topScorer([{"name":"Asha","score":"9"},{"name":"Ravi","score":"10"}]) → "Ravi"
plain case
- topScorer([{"name":"Meera","score":"40"},{"name":"Kabir","score":"75"}]) → "Kabir"
Hints 0/3
// Rows come from a CSV export, so every field is a string: { name: "Asha", score: "87" }.
// Returns the name with the highest score (the first one on a tie), or null for no rows.
function topScorer(rows) {
let best = null;
for (const row of rows) {
if (best === null || row.score > best.score) best = row;
}
return best === null ? null : best.name;
}
Ctrl/⌘+Enter runs, Ctrl/⌘+Shift+Enter submits. In the editor, Ctrl+M switches Tab to moving focus.
Run works without an account. Log in to submit against the hidden tests and track your accuracy per bug type.
Ready for pressure? Try a timed set: six snippets, 20 minutes, no hints.