Which fix removes the subtle bug?
const idx = {};
for (const r of rows) idx[r.id] = r;
const ordered = Object.keys(idx);
- Use a
Mapto keep insertion order - Use a
Setto keep insertion order - Sort the keys after collecting them
- Convert every id to a string first
Integer-like object keys are ordered numerically, not by insertion; a Map preserves order.
Play Problem Solving ▸