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

253
Visualizações
Comprenda el siguiente ejercicio de bucles js y cadenas en matriz

Estoy tratando de dar sentido al siguiente ejercicio de javascript, pero parece que no puedo entenderlo, todo lo que sé por ahora es que puedo acceder a cada cadena con "acróstico [i]" donde i sería el número en la matriz, pero no sé a dónde ir desde allí.

 const acrostic = [ "Give me your patience, sister, while I frame", "Exact in capitals your golden name;",, "Or sue the fair Apollo and he will", "Rouse from his heavy slumber and instill", "Great love in me for thee and Poesy.", "Imagine not that greatest mastery", "And kingdom over all the Realms of verse,", "Nears more to heaven in aught, than when we nurse", "And surety give to love and Brotherhood.", " ", "Anthropophagi in Othello's mood;", "Ulysses storm'd and his enchanted belt", "Glow with the Muse, but they are never felt", "Unbosom'd so and so eternal made,", "Such tender incense in their laurel shade", "To all the regent sisters of the Nine", "As this poor offering to you, sister mine.", " ", "Kind sister! aye, this third name says you are;", "Enchanted has it been the Lord knows where;", "And may it taste to you like good old wine,", "Take you to real happiness and give", "Sons, daughters and a home like honied hive." ]; /* Declare a variable that will return the final string */ let georgianaAugustaKeats = "acrostic[i][0]"; for (let i = 0; i < acrostic.length; i += 1) { /* add each first character of each string to the array to the georgianaAugustaKeats variable*/ } console.log(georgianaAugustaKeats);
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Si bien las otras respuestas son correctas, creo que no son aptas para principiantes.

Si todo lo que necesita hacer para el ejercicio es reemplazar la parte comentada en el ciclo for , entonces es simplemente:

 let georgianaAugustaKeats = ""; for (let i = 0; i < acrostic.length; i += 1) { georgianaAugustaKeats += acrostic[i][0]; } console.log(georgianaAugustaKeats);

NOTA: La tercera cadena termina con un ,, , no estoy seguro de que sea intencional. Eso hará que este código genere un error (porque la cadena está vacía, no hay un primer elemento). Puede explicarlo fácilmente, pero creo que es otra pregunta.

about 4 years ago · Juan Pablo Isaza Relatório

0

Puede usar map() con algo de desestructuración para generar una matriz que contenga la primera letra de cada línea y luego join() esa matriz en una cadena:

 const acrostic = [ "Give me your patience, sister, while I frame", "Exact in capitals your golden name;", "Or sue the fair Apollo and he will", "Rouse from his heavy slumber and instill", "Great love in me for thee and Poesy.", "Imagine not that greatest mastery", "And kingdom over all the Realms of verse,", "Nears more to heaven in aught, than when we nurse", "And surety give to love and Brotherhood.", " ", "Anthropophagi in Othello's mood;", "Ulysses storm'd and his enchanted belt", "Glow with the Muse, but they are never felt", "Unbosom'd so and so eternal made,", "Such tender incense in their laurel shade", "To all the regent sisters of the Nine", "As this poor offering to you, sister mine.", " ", "Kind sister! aye, this third name says you are;", "Enchanted has it been the Lord knows where;", "And may it taste to you like good old wine,", "Take you to real happiness and give", "Sons, daughters and a home like honied hive." ]; const result = acrostic.map(([first]) => first).join(''); console.log(result);

about 4 years ago · Juan Pablo Isaza Relatório

0

Puede usar Array.prototype.reduce() combinado con la asignación de desestructuración

Código:

 const acrostic = [ 'Give me your patience, sister, while I frame', 'Exact in capitals your golden name;', , 'Or sue the fair Apollo and he will', 'Rouse from his heavy slumber and instill', 'Great love in me for thee and Poesy.', 'Imagine not that greatest mastery', 'And kingdom over all the Realms of verse,', 'Nears more to heaven in aught, than when we nurse', 'And surety give to love and Brotherhood.', ' ', "Anthropophagi in Othello's mood;", "Ulysses storm'd and his enchanted belt", 'Glow with the Muse, but they are never felt', "Unbosom'd so and so eternal made,", 'Such tender incense in their laurel shade', 'To all the regent sisters of the Nine', 'As this poor offering to you, sister mine.', ' ', 'Kind sister! aye, this third name says you are;', 'Enchanted has it been the Lord knows where;', 'And may it taste to you like good old wine,', 'Take you to real happiness and give', 'Sons, daughters and a home like honied hive.', ] /* Declare a variable that will return the final string */ const result = acrostic.reduce((a, [f]) => a + f, '') console.log(result)

about 4 years ago · Juan Pablo Isaza Relatório
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