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

Which fix removes the subtle bug?

const idx = {};
for (const r of rows) idx[r.id] = r;
const ordered = Object.keys(idx);
  1. Use a Map to keep insertion order
  2. Use a Set to keep insertion order
  3. Sort the keys after collecting them
  4. Convert every id to a string first
Integer-like object keys are ordered numerically, not by insertion; a Map preserves order.
Play Problem Solving ▸