Learning guides / AI coding courses

Coding practice · about 30 minutes

Review an AI-generated diff against its contract

Inspect a fictional patch that changes numeric sorting into text sorting, then catch the regression with a discriminating test.

Is this the next skill you need?

Choose this when you accept changes because they look shorter or their explanation sounds convincing. Prioritize code-review exercises with counterexamples and unchanged requirements.

Preparation: You can read a small array function and a diff. Node.js 20 or newer is enough; you can review the patch with or without an AI assistant.

The time is our planning estimate for this small exercise, not a measured course completion time. If setup takes your whole session, save the command and error, then return after practicing the basics.

Your task and starter files

An imagined assistant proposes removing the comparator from an ascending numeric sort. Existing checks with single-digit inputs still pass. The required behavior is numeric ascending order without mutating the caller array.

Download the original exercise ZIP

1,660 bytes · README, source, checks and reference answer. Extract the ZIP into one folder. Run the commands from that folder. No npm install or paid tool is needed.

node --test task.test.mjs

Expected initial result: Exactly one supplied code test fails; preserve all tests when repairing the code.

The examples are invented for learning. They are independent of provider courses and can be attempted without an AI assistant. If you use one, keep the requirement and supplied checks visible, then review its actual changes.

Work through it

  1. Read proposed.diff before running the code. Write the intended ordering for [10, 2, 1].
  2. Run the tests. Identify the single-digit case that fails to expose the defect and the multi-digit case that does.
  3. Restore the numeric comparator in task.mjs. Keep the array copy so callers retain their original ordering.
  4. Run all checks and write a review comment naming the faulty line, a counterexample and the required repair.

Check your result

Open the worked answer after your attempt

[10, 2, 1] must produce [1, 2, 10]. JavaScript sort without a comparator uses string ordering, producing [1, 10, 2] here. Preserve [...values] and sort with (a, b) => a - b.

The ZIP includes a reference implementation or reference JSON. Use it to compare your reasoning after an attempt; a copied answer does not show that you can perform the task independently.

Keep as evidence: the original observation, your changed code or completed worksheet, the exact command and output, and a short explanation of the decision. When tests begin with one failure, the same unchanged tests should all pass after the repair. For the refactor, checks should pass both before and after.

Scope: The contract covers finite numbers only. NaN, mixed text and locale-aware ordering need separate requirements and checks. This is an original fictional patch, not an observed failure of any named coding tool.

Choose a lesson from the gap you found

If the exercise was hard because you could not run the code, work on language and command-line basics first. If running it was easy but explaining the change was hard, focus on the matching workflow lesson and repeat with fresh inputs.

Cursor Learn has official material on understanding code, developing changes, debugging, and reviewing work. Claude Code 101 covers agent context and a structured coding workflow. Use those lessons for instruction and this independent fixture to check your own result.

Public lesson access and tool usage are separate. Check current pricing, account requirements and usage limits before using either tool. A paid course is most useful when its assignments address the specific step you could not complete.

Find courses for a coding-assistant workflow →

Check the starting skills · Check free and paid access · Choose Claude Code or Cursor first

Sources and authorship

Original AI Course Rank tasks and editorial learning recommendations, published 11 November 2026. Official learning topics checked on that date: Cursor Learn, Claude Academy. The Node.js test-runner documentation explains the built-in testing command. These small tasks are practice evidence, not validated assessments or tool performance comparisons.