Created
August 7, 2019 02:10
-
-
Save parzibyte/ed2e968ad206c8aba8474b34c362713d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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