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

238
Visualizações
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 à 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