$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #215

Which fix removes the bug?

const users = [{ id: 1 }, { id: 1 }];
const unique = [...new Set(users)];
console.log(unique.length); // expected 1
  1. Spread users into a new array
  2. Use a WeakSet instead here
  3. Sort users before the Set
  4. Key a Map by each user.id
A Set compares objects by reference, and the two literals are different objects.
Play Problem Solving ▸