I need to filter an array by multiple filters. All works so far. But is there a more elegant/effective way of doing this? If a filter is empty it should not be returned in the filter result:
this.filteredList = this.constList.filter(function(r) {
if(this.regionFilterValue && this.filterVBundle && this.filterAccountSizeValue){
return r.Region__c === this.regionFilterValue && r.vertical_bundle__c === this.filterVBundle && r.EO_Account_Size__c === this.filterAccountSizeValue;
}
else if(this.regionFilterValue && this.filterVBundle && !this.filterAccountSizeValue){
return r.Region__c === this.regionFilterValue && r.vertical_bundle__c === this.filterVBundle;
}
else if(this.regionFilterValue && !this.filterVBundle && this.filterAccountSizeValue){
return r.Region__c === this.regionFilterValue && r.EO_Account_Size__c === this.filterAccountSizeValue;
}
else if(!this.regionFilterValue && this.filterVBundle && this.filterAccountSizeValue){
return r.vertical_bundle__c === this.filterVBundle && r.EO_Account_Size__c === this.filterAccountSizeValue;
}
else if(this.regionFilterValue && !this.filterVBundle && !this.filterAccountSizeValue){
return r.Region__c === this.regionFilterValue;
}
else if(!this.regionFilterValue && this.filterVBundle && !this.filterAccountSizeValue){
return r.vertical_bundle__c === this.filterVBundle;
}
else if(!this.regionFilterValue && !this.filterVBundle && this.filterAccountSizeValue){
return r.EO_Account_Size__c === this.filterAccountSizeValue;
}
}, this);
Now two more filters are wanted, so the combinations get a little too many.