16
rated 0 times
[
23]
[
7]
/ answers: 1 / hits: 22526
/ 6 Years ago, mon, december 3, 2018, 12:00:00
I'm trying to understand how sorting an array in random order works. So, I found the following code:
var as = [max,jack,sam];
var s = as.sort(func);
function func(a, b) {
return 0.5 - Math.random();
}
console.log(s);
my main question is why they use 0.5 not another number?
and how it really works
More From » arrays