Reputation: 1577
Currently, I use the below filter to return some data list within the given date range. Actually, in the component, I checked only list length and according to that, assing True and False for the variable. I need to know how to convert this directly return boolean and is that way is correct?
export const selectModel = (planedDate: Date) => createSelector(
selectDrugReviews,
(reviews: ReviewModel[]) => reviews.filter(date => date.startDateTime.getTime() <= planedDate.getTime() && (date.endDateTime !== undefined ? date.endDateTime.getTime() >= planedDate.getTime() : true))
);
Upvotes: 0
Views: 1181
Reputation: 4127
Try this
export const selectModel = (planedDate: Date) => createSelector(
selectDrugReviews,
(reviews: ReviewModel[]) => reviews.map((date) => date.startDateTime.getTime() <= planedDate.getTime() && (date.endDateTime !== undefined ? date.endDateTime.getTime() >= planedDate.getTime() : true))
);
Upvotes: 1
Reputation: 30625
you need to use pipe map
rather then filter.
map((date) => <condition here>));
Upvotes: 1