EasyJavaScriptPractice mode: untimed, 3 hints
First overdue invoice
firstOverdue(invoices, today) returns the id of the first invoice that is unpaid and due before today, or null if there is none. Dates are "YYYY-MM-DD" strings, which compare correctly as text.
The code has exactly one planted bug. Reproduce it with the tests, fix it with the smallest change, then submit.
Visible tests
paid invoice first
- firstOverdue([{"id":"A","due":"2026-01-10","paid":true},{"id":"B","due":"2026-01-05","paid":false}], "2026-02-01") → "B"
not due yet
- firstOverdue([{"id":"C","due":"2026-03-01","paid":false}], "2026-02-01") → null
Hints 0/3
// Returns the id of the first unpaid invoice that is past its due date, or null.
// Dates are "YYYY-MM-DD" strings, so they compare correctly as text.
function firstOverdue(invoices, today) {
for (const inv of invoices) {
if (!inv.paid && inv.due < today) {
return inv.id;
} else {
return null;
}
}
return null;
}
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.