I am doing an exercise for a job and I have a problem when messing an array. That is, I have an array called "numbers" and a function that messes up. Then I create an empty array called "disordered numbers" which I will fill with three positions, which will be three times the array "numbers" messed up differently. Why when I create the positions of the array "disordered numbers" with the function of cluttering the "numbers" array, does it always create the same clutter? I show you code and the result:
function desordenar(array){
array = array.sort(function() {return Math.random() - 0.5});
return array;
} // esta función me desordena un array
var numeros= ["1", "2", "3", "4", "5"]; //este es mi array
numerosDesordenados= []; // array vacio
for (i=0;i<3;i++){ //creo bucle para llenar array vacío
numerosDesordenados[i] = desordenar(numeros);
}
If I do a console.log(numeros)
it shows me in console ["1, "2", "3", "4", "5"]
. Well ... If I do a console.log(numerosDesordenados)
it shows me an array with three positions always with the same mixture, for example:
[0] = ["2","3","1","5","4"]
[1] = ["2","3","1","5","4"]
[3] = ["2","3","1","5","4"]
I want the three positions to be different. How can I do it?? Thank you very much!