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

338
Vistas
React native .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()

This is my current code. It currently prints a random array of the "random" numbers, how ever im trying to print all the available numbers without any one number repeating itself inside of the "rnum" array. If anyone could help me out id be gratefull!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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) 

I solved the problem by using Samuel Goldenbaum's suggestion to look at a previous solution in JS "How to randomize (shuffle) a JavaScript array?". I simply had tu replace all replace "array" with "this"!

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