Reputation: 49
I want to return not one date but all the task that has ended.
Assumning my end_date Task are
Jan. 30 2020
Jan. 30 2017
Jan. 30 1987
so far the code below only return
My code is
const CalTaskHasEnded = Task => {
return new Date(task.end_date).getDay() === new Date().getDay();
};
But this only returns one date from the list of dates where task has ended.
How to write this code to be able to return all the tasks that has gotten its end_date. i.e task that has ended.
Upvotes: 0
Views: 212
Reputation: 49
Thanks RamiReddy for your time, I have solved this like this
const calTaskHasEnded = Task => {
if (task.has_ended){
return new Date().getDay();
}
};
Upvotes: 0
Reputation: 2028
you can check date before or not
const CalTaskHasEnded = (task:Task ) => {
return new Date(task.end_date).getTime() <= new Date().getTime();
};
let tasks = [{
end_date:'Jan. 30 2020'
},{
end_date:'Jan. 30 2017'
},
{
end_date:'Jan. 30 1987'
},
{
end_date:'Jan. 30 2027'
}]
console.log(tasks.filter(CalTaskHasEnded));
Upvotes: 2