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

331
Vistas
How to repeat random string with .repeat() and make it still random?

Is there some way to make random strings with .repeat() still random? If I use this:

console.log(`${Math.random()} | `.repeat(5));

the output is something like this:

0.2564646392254777 | 0.2564646392254777 | 0.2564646392254777 | 0.2564646392254777 | 0.2564646392254777 | 

In a nutshell, the output is the same.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

What your code currently does is:

  1. Generate a random number within a string
  2. Repeat n times that string.

What you want is generate n random number strings, then join them.

Here is a function that does this:

function randomNumberString(n) {
    return Array(n).fill(0).map(_ => `${Math.random()}`).join(' | ');
}
console.log(randomNumberString(10));

And if you really want the | at the end:

function randomNumberString(n) {
    return Array(n).fill(0).map(_ => `${Math.random()} | `).join('');
}
console.log(randomNumberString(10));

about 4 years ago · Santiago Trujillo 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