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

340
Views
Reaccionar nativo .shuffle()
export default function App() { Array.prototype.shuffle = function () { let rnum=[] let random = this for (let i= 0; i < random.length; i++){ let randomizer = Math.floor(Math.random()*(this.length)); rnum.push(randomizer) } console.log(rnum) } let random = [0,1,2,3,4].shuffle()

Este es mi código actual. Actualmente imprime una matriz aleatoria de los números "aleatorios", sin embargo, estoy tratando de imprimir todos los números disponibles sin que ningún número se repita dentro de la matriz "rnum". ¡Si alguien pudiera ayudarme, se lo agradecería!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 let index= this.length, randomIndex while(index != 0) { randomIndex = Math.floor(Math.random()*index) index-- [this[index], this[randomIndex]] = [this[randomIndex], this[index]] } return this } var random = [0,1,2,3,4].shuffle() console.log(random)

Resolví el problema utilizando la sugerencia de Samuel Goldenbaum para ver una solución anterior en JS "¿Cómo aleatorizar (barajar) una matriz de JavaScript?". ¡Simplemente tuve que reemplazar todo reemplazar "matriz" con "esto"!

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