Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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