JavaScript Map and Set for Pythonistas (Summary)

Congratulations, you made it to the end of the course! Rosa’s garden report now runs in JavaScript. With the seed swap finished, garden-report.js prints the same fourteen lines as garden_report.py. Plot three goes to Dev Patel, member 214, and the report closes with “Seed swap, section D: nothing yet”.

The empty section gets a line, runner beans get a zero, and the waiting list keeps the order in which people asked to join. In this course, you learned how to:

  • Keep the waiting list’s number keys and insertion order with a Map, and update or check entries with .set(), .delete(), and .has()
  • Choose an object for a plot’s named fields and a Map for a lookup keyed by data, then save this Map’s ordered number-and-name pairs with JSON.stringify([...waiting])
  • Count show entries in a Map, reading a missing count as zero with ?? 0, where Python’s Counter supplies the zero
  • Group plots with Object.groupBy() or Map.groupBy(), and read a missing section as an empty array with ?? []
  • Combine Sets with .union(), .intersection(), and .difference(), and compare their members with .isSubsetOf() and .isDisjointFrom()
  • Build a Map of Sets with .getOrInsert() and deep-copy its nested data with structuredClone(), where Python uses a defaultdict(set) and copy.deepcopy()

Each choice lets the report answer the same question as the Python script, even when the JavaScript expression looks different.

Choose What the Keys Mean

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.