Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

351
Vistas
To finish the function scrollingText(word)

I am writing a program where I want the following result:

[ 'ROBOT', 'OBOTR', 'BOTRO', 'OTROB', 'TROBO' ]

Now I have:

[ 'robotr', 'obotr', 'botr', 'otr', 'tr' ]

Where am I going wrong? Here is my code:

function scrollingText(word) {
  word = word.toUpperCase();
  let arr = [];
  for (let i = 0; i < word.length; i++) {
    arr.push(word[i] + word.slice(i + 1) + word[0]);
  }
  return arr;
}

console.log(scrollingText('robot'));

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to update word in each iteration, and not merely slice the same word repeatedly. Here is my snippet:

function scrollingText(word) {
  let arr = [word.toUpperCase()]; // storing original word
  let wordLength = word.length;

  for (let i = 0; i < wordLength - 1; i++) { // iterating for one less than the string length, in this case, from 0 to 3
    word = word.slice(1) + word[0] // <<-- update word in every iteration
    arr.push(word.toUpperCase());
  }

  return arr;
}

console.log(scrollingText('robot'));

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda