I'm trying to do a multiple filter in javascript. It consists in 5 filters: search input, maxYear, minYear and if a string contains one item of an array of strings (x2).
I started doing this:
let entries = formattedJsonResults;
if (search) {
const filtered = entries.filter(entry =>
entry.title.toLowerCase().includes(search.toLowerCase())
);
entries = filtered;
} else if (minYear) {
const filtered = entries.filter(entry =>
Number(entry.date.slice(0, 4)) >= minYear.getFullYear()
);
entries = filtered;
} else if (maxYear) {
const filtered = entries.filter(entry =>
Number(entry.date.slice(0, 4)) <= maxYear.getFullYear()
);
entries = filtered;
}
But later I realized that they are not compatible. Eg, if search exists, I'll never access to the minYear filter.
Can someone help me please? thanks
search, etc?