When dealing with an array of Month/Day/Year datestrings like the one below...
const array1 = ["05/31/2022", "06/01/2022", "06/02/2022"]
...my goal is to modify the array to exclude any datestrings (starting with 01 as the Day) that come after datestrings with 31 as the Day. Similarly, I want to remove instances of Day 30 followed by Day 01.
To achieve this, I loop through the strings in the array using a for statement. I then split each array item by "/" to separate MM, DD, and YYYY into individual variables.
for (let i = 0; i < array1.length; i++) {
var [month, day, year] = array1[i].split('/');
console.log(month, day, year)
}
Next, I plan to create a conditional that identifies if a date with 30 or 31 as the day is followed by a date with 01 as the day, enabling me to remove the subsequent 30th or 31st dates. To do this, I recombine month, day, and year into separate array items as shown below:
const newArray = []
for (let i = 0; i < array1.length; i++) {
var [month, day, year] = array1[i].split('/');
newArray.push(month + day + year)
console.log(newArray)
}
This process generates the output:
['05312022', '06012022', '06022022']
However, I'm uncertain how to formulate a condition that checks for a date with 30 or 31 as the day being followed by a date with 01 as the day. What steps should I take to implement this check?