Learning guides / Workflow practice library / Reliability simulations

Original offline coding practice · Reliability simulations

Simulate trailing-edge debounce deterministically

Keep only the final event in each quiet-window cluster.

The behavior you need to preserve

Events have increasing time and value. Emit an event after delay of silence; an event exactly delay later begins a new cluster. Return values only; no timers run.

The defect to investigate: A leading-edge implementation keeps the first value instead of the last.

This is a small fictional repository task, independent of any provider's course assignments. You can work alone or use a coding assistant. The useful result is a change you can explain and checks that distinguish it from the supplied wrong implementation.

Preparation: read a JavaScript function, open a terminal in an extracted folder and use Node.js 20 or newer. Reserve roughly 20–45 minutes for one attempt and review; this is a planning suggestion, not a measured completion time.

Get the runnable project

Download the exercise, cases and reference ZIP

2,092 bytes. The archive contains task.mjs, task.test.mjs, cases.json, inspect.mjs, task.reference.mjs and a README. Extract all files into one folder. No npm install, network request, model API or paid account is needed.

node --test task.test.mjs
node inspect.mjs

Unchanged starter: 2 passing and 1 failing checks out of 3; the test command exits with code 1. The failure is intentional. It is the evidence you will use to judge the repair.

A case that distinguishes the error

Predict the result for this input before opening the reference. Read the written contract literally, including its input domain and boundary rule.

Input

{
  "events": [
    {
      "time": 0,
      "value": "a"
    },
    {
      "time": 2,
      "value": "b"
    },
    {
      "time": 10,
      "value": "c"
    }
  ],
  "delay": 5
}

Expected

[
  "b",
  "c"
]

Starter output

[
  "a",
  "c"
]

The complete cases.json includes 3 fixed examples. Every test also checks that the caller's input stays unchanged. An example can expose one mistake while leaving other input classes untested.

Repair and review the change

  1. Save the original command output and write one sentence connecting the mismatch to the contract.
  2. Trace the relevant operation in task.mjs. Explain why the starter produces the shown output before asking an assistant to change it.
  3. Change only that implementation. Keep the input cases, their expected values and the test file unchanged.
  4. Rerun the test command. The reference result is 3/3 passing checks and exit code 0. A repair should achieve that same result without changing the contract.
  5. Review the diff, save the output and add a fresh example from the declared domain. Write its expected value yourself before running it.

If a suggested change handles an example by hard-coding it, compare that explanation with the other cases. If it changes behavior outside the contract, record the proposed extension separately before adding requirements.

Reference implementation and reasoning

Open after your attempt

A leading-edge implementation keeps the first value instead of the last. The implementation below follows the stated contract; compare its operations with the discriminating input rather than treating its presence as proof that your own change is correct.

export function solve(x) {
  return x.events.filter((e,i)=>i===x.events.length-1||x.events[i+1].time-e.time>=x.delay).map(e=>e.value);
}

Copying this function can make the provided checks pass. To establish useful practice evidence, explain why it returns the expected result and demonstrate one additional case you selected independently.

Other required examples

Fixed input and expected output pairs shipped in the archive
InputExpected output
{
  "events": [
    {
      "time": 0,
      "value": "a"
    },
    {
      "time": 2,
      "value": "b"
    },
    {
      "time": 10,
      "value": "c"
    }
  ],
  "delay": 5
}
[
  "b",
  "c"
]
{
  "events": [
    {
      "time": 0,
      "value": "a"
    },
    {
      "time": 5,
      "value": "b"
    }
  ],
  "delay": 5
}
[
  "a",
  "b"
]
{
  "events": [],
  "delay": 3
}
[]

Use the result to choose your next lesson

If you could not run the command, practice the runtime and terminal first. If the command ran but the mismatch was hard to explain, spend the next session tracing data and assertions. If the repair was straightforward, review a fresh counterexample and make the input domain more explicit.

Cursor's official debugging chapter and Claude Code 101 are further reading for coding-agent workflows. These practice fixtures are our own material, not included provider assessments.

Find a coding-assistant learning route → · Work through a course decision

A coding-assistant workflow differs from building an app that calls an LLM API or studying machine-learning algorithms. Change the goal and your experience in the quiz if either better describes your intended output. Public lesson access and tool usage are separate; check current pricing and account requirements.

Original task and fictional inputs published 11 November 2026. Source and expected results were executed from the downloadable archive. Node.js test-runner documentation supports the command. Official reading links checked on publication date. This small check set covers only the declared fixture contract; production use, security claims and unlisted input domains require further review.