Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
Can I define a variable as any string in an array?

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, "")).

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda