This post may be a bit nerdish, but FYI for anyone interested . When looking over the proposed guide solutions for the pig latin conversion exercise I noticed that none consider ‘qu-’ or ‘squ’ words (e.g., ‘quiet’, ‘squire’). As regex practice I modified one of the given solutions to account for these terms:
function translatePigLatin(str) {
str = str
.replace(/^([aeiou])(.*)/, '$1$2way')
.replace(/^([^u][squ]+|[^u][qu]+|[^aeiou]+)(.*)/, '$2$1ay');
console.log(str)
}
translatePigLatin("squire");
The code then produces iresquay
for ‘squire’, idsquay
for ‘squid’, otequay
for ‘quote’, and so forth.
The next permutation should also account for consonantal/vocalic/semivocalic initial ‘y-’ terms. My inclination is to treat most initial ‘y-’ words as consonantal based on phonetic considerations for common ‘y-’ terms, though they are arguably semivocalic (the above code does not include ‘y’ with the vowel range). However, it is not this simple, as initial ‘y’ in some technical terms is clearly vocalic (e.g., yttrium, ytterbium, ylem; so also some personal names and archaic terms). Perhaps ‘y’ is vocalic immediately before a consonant?
Any thoughts by someone with an English background ?