Is this a safe way to shuffle Javascript Array?

Viewed 45

Unlike python javascript does not have Array.prototype.shuffle()method. So I implemented like below:

var arr = [1, 2, 3, 4, 5];
arr.sort((a, b)=> Math.random() * 2 - 1); //simple shuffle
console.log(arr);

I don't know whether this code is safe enough to use.

0 Answers
Related