Skip to content

Instantly share code, notes, and snippets.

@mattswann
Last active August 29, 2015 14:16
Show Gist options
  • Save mattswann/fae35dac6721373680c2 to your computer and use it in GitHub Desktop.
Save mattswann/fae35dac6721373680c2 to your computer and use it in GitHub Desktop.

###PT PLANNER ####Melbourne Public Transport Journey Planner

There are 3 train lines:

The Alamein line has the following stops: Flinders Street, Richmond, East Richmond, Burnley, Hawthorn, and Glenferrie.

The Glen Waverly line has the following stops: Flagstaff, Melbourne Central, Parliament, Richmond, Kooyong and Tooronga.

The Sandringham line has the following stops: Southern Cross, Richmond, South Yarra, Prahran, and Windsor.


All 3 train lines intersect at Richmond, but there are NO other intersection points as trains run express.

Write a JS program that takes the line + stop that a user is getting on at and the line + stop that user is getting off at and prints the total number of stops for the trip.

#####Hints:

Get your JS program to work for a single line before trying to tackle multiple lines. Consider diagramming the lines by sketching out the train lines and their stops and intersection. Make train lines keys in a hash, while the values are an array of all the stops on each line.

The key to the lab is the intersection of the lines at Richmond.

####Non-Required Bonus:

  • List the stations on the journey in order of travel
  • Use input validation
    • User must enter a line and station in the subway network
    • If the user enters something else, your program should handle it
  • Add an additional lines
  • Allow trains to have multiple intersection points

Resources

Here's a map of the train network to help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment