function shuffle(array) {
**array.sort(() => Math.random() - 0.5);**
}
let arr = [1, 2, 3];
shuffle(arr);
alert(arr);
The function of sort() is an arrow function with no arguments, so I wonder how it works.
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
function shuffle(array) {
**array.sort(() => Math.random() - 0.5);**
}
let arr = [1, 2, 3];
shuffle(arr);
alert(arr);
The function of sort() is an arrow function with no arguments, so I wonder how it works.