thecodezone.
The Code Zone
← Back to the Developer Playbook

Code Zone Bug Lab / Episode 16

The Filter That Changes the Original List

Completed only works. Show all can’t bring the other tasks back.

DEV-159 · Arrays · filter · mutation15–20 minutesNo setup or account required
Switching back to Show all leaves only the completed Build task.
Switching back to Show all leaves only the completed Build task.

Your sprint ticket · In progress · DEV-159

The Filter That Changes the Original List.

Customer report: After filtering completed tasks, the incomplete tasks vanish from the full list.

Steps to reproduce

  1. Start with Plan, Build, Test. Only Build is completed.
  2. Click Completed only.
  3. Click Show all and compare with the original list.

Make a focused behavior fix. Styling and adding unrelated features belong to another ticket.

Acceptance criteria

  • Completed only shows Build.
  • Show all restores Plan, Build, Test in order.
  • Repeated filtering does not remove source data.
  • Filtering does not change the input array or task objects.
  • Empty input produces an empty array.

Learning demo only. No real accounts, purchases, authentication, or external requests.

Reproduce → inspect → hypothesize → verify

Take the ticket.

Reproduce the bug before editing. Inspect the Console and the JS tab. Explain one hypothesis, change the relevant code, then use Check challenge below the editor. Test the full ticket, not only the starter example. Reveal hints one at a time if needed.

Checking account and saved lab work…

Sign in to sync across devices

Loading the JavaScript and HTML editor…

Pass the checks or make three attempts to unlock an explained example.

Ready to test? Choose “Check challenge” after investigating.

    Open starter in a separate tab

    Code and prediction notes recover in this browser and sync when signed in. Instructor examples stay separate. Reset replaces code, not prediction notes.

    One possible solution

    Compare this approach with your own. Opening it does not change your code or mark the exercise complete.

    Return tasks.filter(task => task.done). The starter removes incomplete tasks from the original array using splice. A view should select matching items without deleting the source data. filter creates a new array; its objects are still shared, so avoid changing their properties too.

    Try first. Reveal one clue at a time.

    Need a lead?

    1. Inspect the source after filtering.

    Does completedTasks remove items from the array it was given?

    2. Choose an operation that returns a new array.

    splice mutates. filter returns a new array of matches without removing source items.

    3. Return only completed matches.

    Use tasks.filter(task => task.done). Keep the source array and task properties unchanged.

    Your lab report

    Show your reasoning.

    “I expected… I observed… The console showed… My hypothesis was… I changed… I verified…”

    Use Check challenge for automated behavior checks. Passing checks are useful evidence, not a complete code review.

    Give others room to investigate: label solutions as spoilers.

    Share your lab report on SKOOL (new tab) ↗