Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ed2e968ad206c8aba8474b34c362713d to your computer and use it in GitHub Desktop.
Save parzibyte/ed2e968ad206c8aba8474b34c362713d to your computer and use it in GitHub Desktop.
/**
* Mezclar un arreglo en JavaScript
*
* Visita: https://parzibyte.me/blog
*/
// Nota: esta función modifica al arreglo
// internamente
const mezclarArreglo = arreglo => {
for (let i = arreglo.length - 1; i > 0; i--) {
let indiceAleatorio = Math.floor(Math.random() * (i + 1));
let temporal = arreglo[i];
arreglo[i] = arreglo[indiceAleatorio];
arreglo[indiceAleatorio] = temporal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment