Hello! Here you can find information about the exercise proposed by Stack Builders for an internship position. I hope you like it 💡
Using the language that you feel most proficient in, we’d like you to write a "Pico y Placa" predictor. The inputs should be a license plate number (the full number, not the last digit. e.g. PBX-1234), a date (as a String), and a time. Feel free to choose the date / time format you're comfortable with. The program should return whether or not that car can be on the road. You may use any input and output method you prefer.
Note: To develop this application you need to consider the past rules of the Pico&Placa. (Hours: 7:00am - 9:30am / 16:00pm - 19:30).
For this exercise I focused on the following important points:
- License plate request, vehicle object creation and license plate validation as applicable in Ecuador.
- Date request and validation in the format (MM/DD/YYYY).
- Time request and validation in the format (hh:mm).
- Calculation of result based on the "pico y placa" past time.
- Unit Tests of the algorithm for calculating the result.
In the figure it can be seen that the Model - View - Controller (MVC) architectural pattern was used, which controls the handling of vehicle objects in an excellent way and the code can be organized in a better way.
- The client requests the program to run and enters the inputs.
- The controller receives his request, creates the vehicle object and processes until it receives the response as to whether the vehicle is in restricted hours or not.
- The controller sends the result to the view
- The view is in charge of displaying the result to the client (In this case, the result has been printed by console).
- Obtaining the day of the week according to the requested date by means of the getDay() function.
- Obtaining the last digit of the license plate
- If the day is 0 or 6 (Saturday or Sunday), it will return the warning: "Can circulate".
- Validated by means of a Switch - Case sentence, in each case (1-5), corresponding to the days of the week.
- If the last digit of the license plate coincides with the day, it will be validated if the hour is in the interval where the vehicle cannot drive: 07:00 - 9:30 and 16:00 to 18:30.
- If it coincides with the mentioned time interval, it will return the warning "Can not circulate", otherwise it will return "Can circulate".
- Finally, the results will be saved in a txt file and so we have a log.
Make sure node
& npm
is installed on your system.
git clone https://github.com/jlgalarza3/PicoyPlaca-StackBuilders-Exercise.git
cd .\PicoyPlaca-StackBuilders-Exercise\
code .
Only the jest dependency will be installed for unit testing. Only prompt-sync dependency will be installed to request data
npm install
node .\index.js
npm test