-2
    const getVisibleExpenses = (expenses, { text, sortBy, startDate, endDate }) => {
    return expenses.filter((expense) => {
        const startDateMatch = typeof startDate !== "number" || expense.createAt >= startDate;
        const endDateMatch = typeof endDate !== "number" || expense.createAt <= endDate;
        const textMatch = expense.desciption.toLowerCase().includes(text.toLowerCase())
        return startDateMatch && endDateMatch && textMatch;
    });

}
const store = createStore(combineReducers({
    expenses: expensesReducer,
    filters: filterReducer
}))

store.subscribe(() => {
    const state = store.getState();
    const visibleExpense = getVisibleExpenses(state.expenses, state.filters);
    console.log(visibleExpense);
})

can any one help me to describe this code particularly in this section i got the expenses and object from the redux store which are the reducer but i could not understand the logic of below code

const startDateMatch = typeof startDate !== "number" || expense.createAt >= startDate;
Umair
  • 6,366
  • 15
  • 42
  • 50
  • Possible duplicate of [What does the construct x = x || y mean?](https://stackoverflow.com/questions/2802055/what-does-the-construct-x-x-y-mean) – Don Foumare Dec 28 '18 at 06:22

1 Answers1

0
const startDateMatch = typeof startDate !== "number" || expense.createAt >= startDate;

This means, if the type of startDate is not a number, or is greater than or equal to the expense.createAt date, return a boolean with true.

If one or the other is false, startDateMatch will be false. Both have to be true to return true.

Combining that with the 2 other criteria, if all is true (they match), then true is returned, otherwise if any of them are false, false would return.