I have an array as following
array = [
{
name: 'A'
instructors: [
{
name:'InsA'
}
]
businessUnit: {name:'myBusiness'}
},
{
name: 'B'
instructors: [
{
name:'InsB'
}
]
businessUnit: {name:'myBusinessB'}
}
]
I want to filter this array with the values i have which are also in an array as following
classArr = [A,C,D]
instructorArr = [InsA,InsC,InsZ]
businessName = [myBusinessB,myBusinessX,myBusinessD]
NOTE: These filters can have empty arrays as well. For Ex: businessName = [] .
My current approach is to filter as follows
const filtered = array?.filter(
(activity) =>
classArr?.includes(activity.name) &&
activity.instructors?.some((instructor) =>
instructorArr?.some((instructorFilter) => instructor?.name === instructorFilter),
) &&
businessName?.includes(activity.businessUnit?.name),
);
But the issue is this returns if all conditions are met. Not when just 2 or 1 condition is met. How can i return the filtered array when several or all conditions are met?
&&to||in the filter function ?