Last active
February 28, 2021 09:07
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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