Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the logic errors pattern
The wrong operator, an inverted condition, a formula the right way round but backwards.
What went wrong: A Set compares objects by reference identity, not by structural property values. Two distinct objects with identical ids are treated as distinct values.
The fix: Track seen ids using a Set inside a filter callback: users.filter(u => seen.has(u.id) ? false : (seen.add(u.id), true))
Remember: In JavaScript, new Set(objects) checks reference identity (===), not property equality.
The pattern behind it: logic 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/a42fa4a7-e7c2-4759-b6b7-d8fa6b716178" title="Debugging challenge: Deduplicating objects in array with Set returns duplicates" 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/a42fa4a7-e7c2-4759-b6b7-d8fa6b716178">TryBugHunt</a></p>