Students by City
JavaScript
20 pts
Students by City
Write groupByCity(list). It takes an array of student objects ({ name, city }) and returns a Map from each city to an array of names, in the order the students appear. Then print the Map and, with forEach, one summary line per city. Expected output:
Map(3) { "Asmara" => [ "Selam", "Ruta" ], "Keren" => [ "Abel", "Yonas" ], "Massawa" => [ "Senait", "Merhawi" ] }
Asmara: 2 students
Keren: 2 students
Massawa: 2 students
Checklist
groupByCityreturns a Map with one key per city.- Each city points to an array of names in order.
- Print one summary line per city with
forEach. - Print the Map and the three summary lines.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
