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

241
Vistas
Splicing random elements and forming a new Array out of them

I didn´t find this exact question yet, sorry if it already exists!

I´ve got some trouble with homework, Ive got an array from 1 to 50 and want to choose 6 random numbers out of it. I´m doing that with array.splice([Math.floor(Math.random()*array.length)],1)

which works fine for 1 number, but when i interchange the 1 at the end to a 6, it just chooses a random index and proceeds to splice 6 items in a row. Doing a for loop to get a random number 6 times also works but i can´t think about a proper solution to display 6 item arrays at the end

My goal is to create a new array containing exactly 6 NON REPEATING random items and on top of that, do that as many times as you input in the beginning with a prompt and display the arrays in the console, looking something like this:

[5,7,8,10,12,41] [1,10,22,23,40,42] [1,2,17,19,38,45]

I´d greatly appreciate any help, thanks in advance!

Im really sorry, I forgot to mention, this is in javascript!

about 4 years ago · Juan Pablo Isaza
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