I am faced with an array containing various dates in string format such as "2016-08-12". My goal is to eliminate any dates that have already passed by comparing them to today's date. I am using TypeScript for this task.
Here is a snippet of my datoArray:
["2016-08-02", "2016-08-11", "2016-08-22", "2016-09-10"]
and so on...
Below is the logic I am attempting to apply:
for(var i = 0; i < this.datoArray.length; i++){
this.skoleAar = parseInt(this.datoArray[i].slice(0,4))
this.skoleMaaned = parseInt(this.datoArray[i].slice(5,8))
this.skoleDag = parseInt(this.datoArray[i].slice(8,10))
if(this.skoleAar < currentYear){
this.datoArray.splice(i, 1);
}
if(this.skoleAar == currentYear && this.skoleMaaned < currentMonth){
this.datoArray.splice(i, 1);
}
if(this.skoleAar == currentYear && this.skoleMaaned == currentMonth && this.skoleDag < currentDay){
this.datoArray.splice(i, 1);
}
}
The variables, `currentYear`, `currentMonth`, and `currentDay` are obtained from another function. When logged, they show integer values like 2016 for the year and 8 for the month when extracted from the start of the array. For `currentYear`, `currentMonth`, and `currentDay`, it displays 2016, 11, 20 respectively, representing today's year, month, and day all as integers. However, despite these comparisons of integer values, the conditions inside the "if" statements do not seem to work as expected. It appears there may be an issue with the way I am performing the comparisons. As far as I understand, this should be the correct way to compare integer values, so I am puzzled as to why the logic is failing?