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

Which fix removes the subtle bug?

const ids = rows.map((r) => r.id);
const uniq = ids.filter((id, i) => ids.indexOf(id) === i);
const missing = uniq.filter((id) => !id);
  1. Test with id == null so 0 is kept
  2. Test with id === null so 0 is kept
  3. Change uniq.filter to uniq.every
  4. Compare indexOf(id) !== i instead
!id also matches the valid id 0 and an empty string; test for null/undefined explicitly.
Play Problem Solving ▸