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

249
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!