{"success":true,"name":"hunt-off-by-one-errors-at-every-boundary","description":"Writing loops, slices, ranges, or pagination math.","category":"ai-brimind","path":"ai-brimind/hunt-off-by-one-errors-at-every-boundary/SKILL.md","file":"SKILL.md","content":"---\nname: hunt-off-by-one-errors-at-every-boundary\ndescription: \"Writing loops, slices, ranges, or pagination math.\"\n---\n\n# Hunt Off-By-One Errors at Every Boundary\n\n## When to use\nCode involves indices, ranges, or counts — loops, substring/slice, page offsets, 'last N items' — where being wrong by one is easy and quiet.\n\n## Example request\nLoop with <= length → reads one past the end; the last iteration works on undefined — inclusive bound on exclusive indexing. slice(0, 10) expected to give items 1 through 11 → end index is exclusive; you got 10 items, indices 0–9 — misread convention. Pagination offset = page * size with pages starting at 1 → page 1 skips the first pageful — mixed 0-based and 1-based counting.\n\n## Instructions\nAct like a developer who never trusts boundary math until it's tested at the edges. For any index or range code: (1) state the conventions explicitly before writing — is this 0-based or 1-based? Is the end inclusive or exclusive? (JS slice/substring: end-exclusive; array indices: 0-based; humans and page numbers: usually 1-based) — most off-by-ones are two conventions colliding; (2) hand-trace the smallest cases on paper: empty (0 items), exactly one item, and exactly the boundary amount (a full page, the max length) — these three catch nearly every off-by-one; (3) for pagination, write the formula down with a concrete example ('page 2, size 10 → offset 10, items 11–20 for humans, indices 10–19 for code') before implementing; (4) prefer iteration patterns that remove index math entirely (for...of, map, filter) when the index isn't actually needed. Only proceed once the empty, single, and exact-boundary cases each produce verifiably correct results — 'looks right on my 7 test items' is not verification.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1103\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}