Oct-07-2019, 05:51 PM
I want to make a function that, when passed a string containing a single word, returns that word preceded by the indefinite article "a" or "an," depending on which is correct. This would be easy enough to do if the rule we were taught as kids were correct: "a" before a consonant, "an" before a vowel. But it isn't. It's "a" before a consonant sound and "an" before a vowel sound; hence, "an umbrella" but "a unicorn" (YOO-ni-corn). How would you go about writing this function? Would you try to compile an exhaustive list of "exceptions" from online sources or work with some kind of API or what? Also, how would you find out if someone has already done this?