Code Room
Vibe codingMedium
Question
An AI agent wrote this JavaScript helper to split a charge evenly across N parties and assert nothing is lost, for a payments feature:
function splitAmount(totalDollars, parties) { const share = totalDollars / parties; const shares = Array.from({ length: parties }, () => share); const sum = shares.reduce((a, b) => a + b, 0); if (sum !== totalDollars) throw new Error("split mismatch"); return shares.map((s) => Number(s.toFixed(2)));}It works for `splitAmount(100, 4)`. Why is this dangerous in production, and what's the right approach?
What a strong answer looks like
Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.