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

Which fix removes the bug?

const scores = new Map([['ana', 3]]);
const body = JSON.stringify(scores);
send(body); // sends "{}"
  1. Pass a spacer: JSON.stringify(scores, null, 2)
  2. Spread it first into { ...scores }
  3. Convert first: Object.fromEntries(scores)
  4. Send scores.toString() as the body
A Map has no enumerable own properties, so JSON sees an empty object; convert it to a plain object first.
Play Problem Solving ▸