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

242
Views
Cree cadenas usando literales de plantilla usando el método forEach

¿Puede alguien ayudarme por favor arreglar mi código? Estaba usando el método forEach en este ejercicio

Creo que estoy cerca, pero todavía me da indefinido, ya está dentro del resultado. Fallo porque lo verifiqué agregando otra cadena/número.

 const result = { success: ["max-length", "no-amd", "prefer-arrow-functions"], failure: ["no-var", "var-on-top", "linebreak",], skipped: ["no-extra-semi", "no-dup-keys"] }; function makeList(arr) { // Only change code below this line const failureItems = []; const results = arr.forEach(k => failureItems.push(`<li class="text-warning">${arr[k]}</li>`)); // Only change code above this line return failureItems; } const failuresList = makeList(result.failure); console.log(failuresList);

debe ser resultado de esto

 [ '<li class="text-warning">no-var</li>', '<li class="text-warning">var-on-top</li>', '<li class="text-warning">linebreak</li>' ]

pero en este código mi resultado es este

 [ '<li class="text-warning">undefined</li>', '<li class="text-warning">undefined</li>', '<li class="text-warning">undefined</li>' ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Quiere concatenar k . También como se menciona en los comentarios, Array#forEach devuelve undefined .

Para arreglar lo anterior:

 arr.forEach(k => failureItems.push(`<li class="text-warning">${k}</li>`));

Otra solución usando Array#map :

 function makeList(arr) { return arr.map(k => `<li class="text-warning">${k}</li>`); } const result = { success: ["max-length", "no-amd", "prefer-arrow-functions"], failure: ["no-var", "var-on-top", "linebreak",], skipped: ["no-extra-semi", "no-dup-keys"] }; const failuresList = makeList(result.failure); console.log(failuresList);

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!