Giter Club home page Giter Club logo

hw-w01-d05-js-mbta's Introduction

General Assembly Logo

JS Object Modeling

Objectives

  • Practice with functions, arrays, and objects.

Instructions

  1. Fork and clone this repository.
  2. Create and checkout to a new branch, named homework.
  3. When finished, add, commit and push to your fork to submit a pull request.

Activity

  • Create a file named mbta.js to calculate the number of stops between stations on the "MBTA". Write additional functions used by this function as needed.
  • The function takes the line and stop that a rider is getting on at and the line and stop that a rider is getting off at and returns the total number of stops for the trip.

There are 3 subway lines:

  • Red
    • South Station
    • Park Street
    • Kendall
    • Central
    • Harvard
    • Porter
    • Davis
    • Alewife
  • Green
    • Government Center
    • Park Street
    • Boylston
    • Arlington
    • Copley
    • Hynes
    • Kenmore
  • Orange
    • North Station
    • Haymarket
    • Park Street
    • State
    • Downtown Crossing
    • Chinatown
    • Back Bay
    • Forest Hills
  • All 3 subway lines intersect at Park Street, but there are no other intersection points.

The function will be invoked using the following pattern of arguments:

Start Line, Start Station, End Line, End Station

Here are some examples of how should be invoked.

stopsBetweenStations('Red', 'Alewife', 'Red', 'Alewife') // 0 stops
stopsBetweenStations('Red', 'Alewife', 'Red', 'South Station') // 7 stops
stopsBetweenStations('Red', 'South Station', 'Green', 'Kenmore') // 6 stops

Hints

  • Consider diagramming the lines by sketching out the subway lines and their stops and intersection.
  • Solve an easier problem first like only traveling on the Red line.
  • Assume good input. Your function does not need to check the validity of the line or stop.
  • Subway lines are keys in a dictionary (object literal), while the values are a list (array) of all the stops on each line.
  • The key to the practice is to find the intersection of the lines at Park Street.

Bonus

  • Add validation so that the function only accepts Red, Green, and Orange for lines and only accepts the correct stops for each of their stops.
  • Have the function print the line and stops as they ride the train.
  • Example:
stopsBetweenStations('Red', 'South Station', 'Green', 'Copley') 

// Rider boards the train a Red Line and South Station.
// Rider arrives at Red Line and Park Street.
// Rider transfers from Red Line to Green Line at Park Street.
// Rider arrives at Green Line and Boylston.
// Rider arrives at Green Line and Arlington.
// Rider arrives at Green Line and Copley.
// Rider exits the train at Green Line and Copley.
  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

hw-w01-d05-js-mbta's People

Contributors

micfin avatar usmanbashir avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.