Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!