Skip to content

Instantly share code, notes, and snippets.

@ma-henderson
Last active February 28, 2021 09:07
Show Gist options
  • Save ma-henderson/90f27feaa041077b103b8edaeed6bb57 to your computer and use it in GitHub Desktop.
Save ma-henderson/90f27feaa041077b103b8edaeed6bb57 to your computer and use it in GitHub Desktop.
Take received filters params and return doctors who fit within the criteria (UNION/OR not AND)
filterDoctors = (doctors, filters) => {
let filteredDoctors = [];
if (filters.gender.length > 0) {
filteredDoctors.concat(
filters.gender.map((gender) =>
filteredDoctors.filter((doctor) => doctor.gender == gender)
)
);
}
if (filters.specs.length > 0) {
filteredDoctors.concat(
filters.specs.map((spec) =>
doctors.filter((doctor) => doctor.specializations == spec)
)
);
}
return filteredDoctors.filter(onlyUnique);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment