Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
En JS for loop, ¿cómo sustituir la letra 'a' en la cadena 'begin_a_end' con un elemento de matriz, por ejemplo, 'begin_vowe[i]_end'?

En un javascript for loop, necesito sustituir el guión bajo acotado con Vowels[i] y la cita acotada ā con MacronVowels[i] en:

 flosType_a_withMacron() putMacronedLetter("ā")

Estoy tratando de condensar una serie de cinco funciones con las vocales a,b,c,d,e y ā,ē,ī,ō,ū creando 2 matrices (ver código) y reemplazando (en el bucle for) la función con elementos de la matriz antes mencionados. Obviamente, esto solo me ahorrará unas pocas líneas de código, pero soy relativamente nuevo en la codificación y solo quiero saber cómo hacer esto con fines de aprendizaje.

Aquí están las cinco funciones tal como existen actualmente y funcionan correctamente. Lo que quiero hacer para envolverlos en uno en un bucle for:

CÓDIGO EXISTENTE:

 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); }

CÓDIGO PROPUESTO: (cuál es el formato correcto aquí, esto es obviamente incorrecto, solo pregunto)

 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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!