Skip to content

Instantly share code, notes, and snippets.

@sillygwailo
Last active May 15, 2018 09:07
Show Gist options
  • Save sillygwailo/6913981 to your computer and use it in GitHub Desktop.
Save sillygwailo/6913981 to your computer and use it in GitHub Desktop.
Node module to provide the correct article for words starting with vowels
/*
TODO: * An article that starts a sentence should be capitalized.
* A more comprehensive list of subtleties like "a useful", "a once", "an hour", "an historical"
* Tests
*/
exports.article = function(text) {
var vowels = 'aeiou';
var an_exceptions = ['eucalyptus', 'eunuch', 'euphemism', 'euphemistic', 'euphonium', 'euphoric', 'european', 'once', 'one', 'onesie', 'union', 'unique', 'unison', 'united', 'useful', 'utopia', 'utopic', 'user', 'unicorn'];
var a_exceptions = ['hour', 'historical', 'honorable', 'honourable'];
if (a_exceptions.indexOf(text) != -1 || (vowels.indexOf(text.charAt(1)) == -1 && an_exceptions.indexOf(text) == -1)) {
return 'an';
}
else {
return 'a';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment