Created
April 26, 2020 19:04
-
-
Save omardeleo/aef751147e84dfb9a2dfcf2822738f85 to your computer and use it in GitHub Desktop.
Attempt to sort volunteer records by language and fluency
This file contains hidden or 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
| .sort((a, b) => { | |
| let aLanguage, aProficiency, bLanguage, bProficiency; | |
| const aLanguages = a[0].get("Please list what other languages you speak, if any, and level of fluency. ") | |
| const bLanguages = b[0].get("Please list what other languages you speak, if any, and level of fluency. ") | |
| // console.log(aLanguages) | |
| // console.log(bLanguages) | |
| if (aLanguages) { | |
| for (let language of aLanguages) { | |
| const [lang, prof] = language.split(" - "); | |
| if (lang === requestLanguage) { | |
| aLanguage = lang | |
| aProficiency = prof | |
| } | |
| } | |
| } | |
| if (bLanguages) { | |
| for (let language of bLanguages) { | |
| const [lang, prof] = language.split(" - "); | |
| if (lang === requestLanguage) { | |
| bLanguage = lang | |
| bProficiency = prof | |
| } | |
| } | |
| } | |
| if (aLanguage === requestLanguage && bLanguage !== requestLanguage) { | |
| return -1 | |
| } else if (bLanguage === requestLanguage && aLanguage !== requestLanguage) { | |
| return 1 | |
| } else if (bLanguage === requestLanguage && aLanguage === requestLanguage) { | |
| if (bProficiency === "fluent" && aProficiency !== "fluent") { | |
| return -1 | |
| } else if (aProficiency === "fluent" && bProficiency !== "fluent") { | |
| return 1 | |
| } else { | |
| return a[1] - b[1] | |
| } | |
| } else { | |
| return a[1] - b[1] | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment