The Toast That Never Left — JavaScript Bug Hunt

Inspired by notification trays everywhere: expired toasts that linger forever.

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Medium
  • Concepts: Arrays, Mutation
  • Modelled on: Notification trays
  • Visible tests: adjacent expired toasts are both removed; expiring exactly now counts as expired
  • Reward: 50 XP for a complete fix

Briefing

Inspired by notification trays everywhere: expired toasts that linger forever. Two bugs conspire — the classic splice-while-iterating skip (removing index i shifts the next element into i, then i++ jumps over it), and an exclusive comparison that spares anything expiring exactly now.

toasts.js sweeps the tray.

Bug report

BUG-TOAST · Reported by: design systems

sweep(toasts, now):

  • remove every toast with expiresAt <= now
  • keep the survivors in order

Observed: when two expired toasts sit side by side, only the first is removed; and a toast expiring exactly at the sweep tick survives forever.

Logs

[tray] sweep(now=6): removed 1 of 2 expired

The code as shipped

src/ui/toasts.js (editable)

// Removes expired toasts (mutates and returns the array).
exports.sweep = function (toasts, now) {
  for (var i = 0; i < toasts.length; i++) {
    if (toasts[i].expiresAt < now) {
      toasts.splice(i, 1);
    }
  }
  return toasts;
};

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.