I can't figure out how to filter an array with multiple conditions. I have a search filter form with 2 select, 1 checkboxes fieldset and 1 radio button fieldset. I have functions that return items that match chosen conditions. They work only separately. What is the best approach to find objects that match all conditions?
I tried to make if statements for all possible options, but code doesn't work correctly and it looks like there should be some better options to do so.
Here is function examples:
function chooseRating(hotel) {
return hotel.rating == e.target.value;
}
function chooseMeal(hotel) {
return hotel.mealType == e.target.value;
}
function choosePlace(hotel) {
for (let l = 0; l < chosenPlace.length; l++) {
if(chosenPlace[l].checked) {
return hotel.region == e.target.value;
}
}
}
How should I filter the array with that?
let filteredCards = hotels.filter(function(hotel, index, hotels) {
// ??
});
User chooses his requirements for hotel and he should get hotels, that match all requirements. And if some of them not chosen, then they are don't count by default.