Вы можете взять массив строк для ключей объекта фильтра и, соответственно, функцию для проверки требуемых ключей объекта с их требуемым значением / с.
В функции фильтра итерируйте массив функций ключа ирано выходить, если требуется функция и результат равен true
.
Результатом является массив из 12 объектов из 13 исходных объектов.
var data = [{ MenB_Classification: "NOT Required", CONTROL: "Public", Enrollment: "892" }, { MenB_Classification: "Required", CONTROL: "Private", Enrollment: "1601" }, { MenB_Classification: "NOT Required", CONTROL: "Private", Enrollment: "447" }, { MenB_Classification: "NOT Required", CONTROL: "Public", Enrollment: "1203" }, { MenB_Classification: "Required", CONTROL: "Private", Enrollment: "32" }, { MenB_Classification: "NOT Required", CONTROL: "Public", Enrollment: "98" }, { MenB_Classification: "Recommended", CONTROL: "Private", Enrollment: "654" }, { MenB_Classification: "NOT Required", CONTROL: "33033764030", Enrollment: "345318" }, { MenB_Classification: "NOT Required", CONTROL: "Private", Enrollment: "13324" }, { MenB_Classification: "Recommended", CONTROL: "Private", Enrollment: "39" }, { MenB_Classification: "NOT Required", CONTROL: "Private", Enrollment: "4" }, { MenB_Classification: "NOT Required", CONTROL: "Private", Enrollment: "910" }, { MenB_Classification: "NOT Required", CONTROL: "Private", Enrollment: "23453" }],
filters = {
required: true,
recomended: true,
notRequired: false,
publics: true,
privates: true,
ennrollmentOne: true,
ennrollmentTwo: false,
ennrollmentThree: false,
ennrollmentFour: false,
},
fn = [
['required', o => o.MenB_Classification === 'Required'],
['recomended', o => o.MenB_Classification === 'Recommended'],
['notRequired', o => o.MenB_Classification === 'NOT Required'],
['publics', o => o.CONTROL === 'Public'],
['privates', o => o.CONTROL === 'Private'],
['ennrollmentOne', o => o.Enrollment < 100],
['ennrollmentTwo', o => o.Enrollment >= 100 && o.Enrollment < 1000],
['ennrollmentThree', o => o.Enrollment >= 1000 && o.Enrollment < 5000],
['ennrollmentFour', o => o.Enrollment >= 5000]
],
result = data.filter(o => fn.some(([k, f]) => filters[k] && f(o)));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }