Created
June 21, 2018 17:31
-
-
Save pineapplemachine/64a7dc66370642816a1d902d463c32b1 to your computer and use it in GitHub Desktop.
Determine with moderate confidence whether an English noun should be preceded by "a" or "an"
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
| // Helper to determine if a noun should be preceded by "a" or "an". | |
| // This should produce a sensible result in the majority of cases. | |
| function englishArticle(noun){ | |
| if(!noun || typeof(noun) !== "string"){ | |
| return undefined; | |
| }else if(noun.length === 1){ | |
| return "an"; | |
| }else if(noun.toUpperCase() === noun){ | |
| return "AEFHILMNORSX".indexOf(noun[0]) < 0 ? "a" : "an"; | |
| }else if("AEIOUaeiou".indexOf(noun[0]) >= 0){ | |
| return word.slice(0, 2).toLowerCase === "eu" ? "a" :"an"; | |
| }else if(word[0] === "h" || word[0] === "H"){ | |
| return "EIOeio".indexOf(word[1]) < 0 ? "a" : "an"; | |
| }else{ | |
| return "a"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment