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

276
Visualizações
How do I use forEach to turn an array of strings into a single string
/*Your task in this activity is to implement a function called createParagraph that takes an array of strings, and returns a single string containing all the items in the array separated by a space.*/

/*Your task in this activity is to implement a function called createParagraph that takes an array of strings, and returns a single string containing all the items in the array separated by a space.*/



//Use forEach to create a single paragraph from a list of words.
// This is a list of words
let words = ['Loops', 'are', 'a', 'great', 'way', 'to', 'find', 'elements', 'in', 'an', 'array'];

// TODO: implement this function to return a string containing all words in a paragraph.
function createParagraph(words) {
  let paragraph = '';
  
  return paragraph.forEach(words);
}

// Prints paragraph to console
console.log(createParagraph(words));

// don't change this line
if (typeof module !== 'undefined') {
  module.exports = createParagraph;
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can't use forEach on strings. forEach is meant to be used with arrays

You can make use of join here to join an array.

let words = [
  'Loops',
  'are',
  'a',
  'great',
  'way',
  'to',
  'find',
  'elements',
  'in',
  'an',
  'array',
];

function createParagraph(words) {
  return words.join(' ');
}

console.log(createParagraph(words));

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