Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the off-by-one errors pattern
The loop that runs one time too many, the slice that drops the last item, the index that starts in the wrong place.
What went wrong: slice(0, size) already gives exactly size items, because slice stops before the end index. Subtracting 1 loses one item.
The fix: return arr.slice(0, size);
Remember: slice(start, end) includes start but not end.
The pattern behind it: off-by-one errors.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/373006f4-1691-4550-9f77-d15bcbf8cb90" title="Debugging challenge: First 3 items comes back with only 2" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/373006f4-1691-4550-9f77-d15bcbf8cb90">TryBugHunt</a></p>