Skip to content
Avio Lines
MediumJavaScriptPractice mode: untimed, 3 hints

Remove expired sessions

removeExpired(sessions, now) removes every session whose expiresAt (epoch seconds) is before now from the list, in place, and returns the list.

The code has exactly one planted bug. Reproduce it with the tests, fix it with the smallest change, then submit.

Visible tests

  1. two expired in a row

    • removeExpired([{"id":1,"expiresAt":5},{"id":2,"expiresAt":6},{"id":3,"expiresAt":50}], 10) → [{"id":3,"expiresAt":50}]
  2. nothing expired

    • removeExpired([{"id":1,"expiresAt":50}], 10) → [{"id":1,"expiresAt":50}]

Hints 0/3

    // Removes every session that expired before `now` (epoch seconds) from the list, in place,
    // and returns the same list.
    function removeExpired(sessions, now) {
      for (let i = 0; i < sessions.length; i++) {
        if (sessions[i].expiresAt < now) sessions.splice(i, 1);
      }
      return sessions;
    }
    

    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.