# Refactor Without Changing Behavior

Source: https://coremesh.online/prompts/refactor-code-without-changing-behavior/

Refactor this JavaScript (Node.js 20) code. Goal: readability; keep it fast.

```
function total(items){let t=0;for(let i=0;i<items.length;i++){if(items[i].qty>0){t=t+items[i].qty*items[i].price}}return t}
```

Rules:
- Behaviour must stay exactly the same, including edge cases and error handling.
- Work in small steps; after each step show the code and one line on what changed.
- Do not add features, rename public functions or change the signature.
Finish with a list of cases I should test to prove nothing changed.
