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

144
Visualizações
In JS for loop how substitute letter, 'a' in string 'begin_a_end' w/ array element, e.g., 'begin_vowe[i]_end'?

In a javascript for loop, I need to substitute the underscore bounded a with Vowels[i] and the quote bounded ā with MacronVowels[i] in:

flosType_a_withMacron()
putMacronedLetter("ā")

I am trying to condense a series of five functions with vowels a,b,c,d,e and ā,ē,ī,ō,ū by creating 2 arrays (see code) and replacing (in the for loop) the function with aforesaid array elements. Obviously this will only save me a few lines of code but I relatively new to coding and just want to know how to do this for learning purposes.

Here are the five functions as they current exist and work correctly. What I want to do in wrap them into one in a for loop:

EXISTING CODE:

        function type_a_withMacron() {
                    putMacronedLetter("ā");
                    moveCursorToEnd(element);
        }               
        function type_e_withMacron() {
                    putMacronedLetter("ē");
                    moveCursorToEnd(element);
        }                                   
        function type_i_withMacron() {
                    putMacronedLetter("ī");
                    moveCursorToEnd(element);
        }
        function type_o_withMacron() {
                    putMacronedLetter("ō");
                    moveCursorToEnd(element);
        }
        function type_u_withMacron() {
                    putMacronedLetter("ū");
                    moveCursorToEnd(element);
        }

PROPOSED CODE: (what is proper formatting here, this is obv wrong, just asking)

const flos_Vowels = ["a","b","c","d","e"];
const flos_MacronVowels = ["ā","ē","ī","ō","ū"];
       
for(let i = 0;i < 5;i++ )
{
    function flosType_flos_[Vowels[i]]_withMacron()
    {
        putMacronedLetter("[flos_MacronVowels[i]]");
        moveCursorToEnd(element);
    }
}
about 4 years ago · Santiago Gelvez
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