I have the following problem. I have an array:
const dates = ["19-June-2019", "18-June-2019", "17-June-2019", "16-June-2019", "14-June-2019"]
I need to generate an array of date that are after I mean dates in row. So:
const datesInRow = ["19-June-2019", "18-June-2019", "17-June-2019", "16-June-2019"]
Here is my initial function: (isAfter function = date-fns)
function numberOfDaysInRow(arr) {
if (arr.length === 1) return arr;
let numberOfDaysInRowArr = [];
for (let i = 0; i < arr.length; i++) {
if (isAfter(new Date(arr[i]), new Date(arr[i + 1]))) {
numberOfDaysInRowArr.push(arr[i]);
}
}
return numberOfDaysInRowArr;
}
This returns only partial answer. For example If I have only two string in array like this:
const dates = ["19-June-2019", "18-June-2019"]
It will return
["19-June-2019"]
which is not what I want.
["19-June-2019", "18-June-2019", "17-June-2019", "16-June-2019", "14-June-2019", "10-June-2019", "09-June-2019"]for example... Will strings10-June-2019 and 09-June-2019be included on the final array?