Kernix13 / springfield-leaf-pickup

Calculates the Aututmn leaf pickup schedule for all the zones in Springfield Township, Pennsylvania.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

springfieldleafpickup

GitHub language count GitHub top language GitHub top language GitHub commit activity GitHub contributors

This is a simple JavaScript application to calculate the schedule each year for leaf pickup in Springfield Township, Pennsylvania.

Reason for the project

I thought it would be a good exercise to write some JavaScript to calculate the schedule.

I started it when I was searching for the 2021 scheule and found two online PDF files for the previous years. I noticed a pattern, had to make some assumptions, then used JavaScript to output the schedule based on the current year.

I contacted the township about a version of this on CodePen but they did not get back to me.

The assumptions

I had to make assumptions because Springfield Township never replied to my email:

  1. The 1st week of leaf pickup is the week of the first Monday in November. But what if November 1st is on a Tuesday such as 2022? Will the 1st week start on Monday October 31st or the follwoing week on Monday November 7th? YES, for 2022! I need to make a change to fix the date calculation
  2. The number of precints do not increase or decrease.
  3. The order that precincts follow in the schedule is constant and does not change.
  4. The number of precincts per week does not change.
  5. The two holiday weeks (week 2 and 4) only have 3 precinct while the other weeks have 4.
  6. The number of weeks of leaf pickup (currently 6) does not change.

If 1 or more of those assumptions are wrong then this will NOT output the correct schedule. Based on the 2 PDF files I found online and some logic, I think my assumptions are correct.

Refactor

Take a look at the commit before my refactoring to see the before and after of this project.

NOTE: This was a project early in my JavaScript studies. Until I refactored it, it did not have a single function - and it worked! How ridiculous is that? I believe the original code is known as imperative code.

  1. Changed main for loop to a map() function.
  2. Changed 18 let keywords to const
  3. Converted the "check the current year and update the startYr variable" code block into the function yearCheck(yr)
  4. Created function findFirstMonday(day) and added the switch statement inside
  5. Created the function currYrSched(num) and added inside the code that gets the current years schedule.
  6. Created the function outputSchedule(arr) and added the code that outputs the <li> items based on the weekely indices.
  7. Removed all console.log statements.

About

Calculates the Aututmn leaf pickup schedule for all the zones in Springfield Township, Pennsylvania.


Languages

Language:JavaScript 63.8%Language:HTML 25.3%Language:CSS 10.9%