I'm working on a function that needs to return an array of elements based on certain filters. Here is the code for the function:
filter_getCustomFilterItems(filterNameToSearch: string, appliedFilters: Array<any>) {
let tempFilterArray = [];
let masterFilterList = getMasterFilterList();
// More details about the variables used in the function
for (let masterFilterItem of masterFilterList) {
// Missing logic section
}
}
I need to filter the masterFilterList
to get an array of items where filterNameToSearch = 'Item2'
under specific conditions:
1) For each element in appliedFilters
, compare appliedFilterItem.name
with
masterFilterItem[appliedFilterItem.name]
and check if any of the filters in appliedFilterItem
have the same value as masterFilterItem[appliedFilterItem.name]
2) The condition should resemble something like
masterFilterItem[appliedFilterItem[0].name] == appliedFilterItem[0].filters[0].value && appliedFilterItem[0].filters[0].status === 'selected' && masterFilterItem[appliedFilterItem[1].name] == appliedFilterItem[1].filters[0].value && appliedFilterItem[1].filters[0].status === 'selected' and so on for all appliedFilterItems
. The number of elements in appliedFilters
is dynamic.
If anyone could assist me with this problem, it would be greatly appreciated.