Porting the Night-Bus Report
In this project, you ported the night-bus report’s first three sections from Python to JavaScript, and left the supervisors for the exercise.
| Python | JavaScript |
|---|---|
"route": "N3", False |
route: "N3", false |
for trip in trips: |
for (const trip of trips) |
late.append(line) |
late.push(line) |
enumerate(late, start=1) |
late.entries(), printing index + 1 |
dict.fromkeys(routes, 0) |
a short loop that starts each route at 0 |
totals.items() |
Object.entries(totals), destructured in the header |
for...else search |
.find(), then if...else on undefined |
- Every loop header declares its variable. Leave the
constout, and the module stops withReferenceError: trip is not defined, because ES (ECMAScript) modules run in strict mode. - Route names keep their order in an object. Keys written as plain whole numbers, such as hours,
come out sorted, and a
Mapkeeps them in order. - Ported with
} else {after the loop, the file stops withSyntaxError: Unexpected token 'else'. JavaScript checks the whole file before it runs any of it, so even the sections above the loop don’t print.
Here are the report’s sections in JavaScript, as you left them. They read last night’s trips,
which the full file at the end of this page lists: