I am trying to make a sound change applier in Javascript (just for practice really as I am still a beginner at JavaScript so excuse if I am making an obvious mistake.) where words from a Proto-language are fed through several functions applying sound changes to generate the words in the daughter language. This is working except for one sound change in particular where a short vowel is lost if the preceding syllable contains a stressed syllable and if the following syllable contains another vowel (e.g sígames > sígmes).
I have made three arrays for each syllable and all possible vowels that can occur in each:
let stressVowels = ["í", "ý", "é", "á", "ó", "ú", "ī́", "ȳ́", "ḗ", "ā́", "ṓ", "ū́"];
let shortVowels = ["i", "y", "e", "a", "o", "u"];
let vowels = ["i", "y", "e", "a", "o", "u", "ī", "ȳ", "ē", "ā", "ō", "ū"];
This is the function I am using for this sound change:
function losePostTonicVowel(list) {
let stressedVowelValue = 0;
let shortVowelValue = 0;
let vowelValue = 0;
let stressedVowel = "";
let shortVowel = "";
let vowel = "";
stressVowels.forEach(function(syllable) {
stressedVowel = syllable;
});
shortVowels.forEach(function(syllable) {
shortVowel = syllable;
});
vowels.forEach(function(syllable) {
vowel = syllable;
});
list.forEach(
function(word) {
stressedVowelValue = word.indexOf(stressedVowel);
shortVowelValue = word.indexOf(shortVowel);
vowelValue = word.indexOf(vowel);
if (shortVowelValue == stressedVowelValue + 2 && shortVowelValue == vowelValue - 2) {
eleventhArray.push(word.replace(shortVowel, ""))
} else {
eleventhArray.push(word);
}
}
)
}
My idea was to use .indexOf(); to determine the index value of each vowel to make sure they were all in the correct position. My main problem is that in each .indexOf() I have passed a variable that refers to a string in each array. It loops through the array so it only returns the final string in the array, but I need it to refer to any string in the array because it could represent any vowel listed in the array. I am very unsure of how to achieve that effect so any help would be very appreciated.
Also I am wondering if it is correct to use a variable inside .replace() as I have done in the line eleventhArray.push(word.replace(shortVowel, "")).