A
arr = Array.from(Array(10).keys());
(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
arr.shuffle()
(10) [4, 3, 9, 5, 0, 1, 8, 2, 6, 7]
Size: a a a
A
arr = Array.from(Array(10).keys());
(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
arr.shuffle()
(10) [4, 3, 9, 5, 0, 1, 8, 2, 6, 7]
МТ
DK
Object.defineProperty(Array.prototype, 'shuffle', {
value: function() {
for (let i = this.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[this[i], this[j]] = [this[j], this[i]];
}
return this;
}
});
A
МТ
МТ
0 - Math.random()
переворачивает массив1 - Math.random()
оставляет массив неизмененным0.5 - Math.random()
равномерно шафлит массив.D
D
D
A
МТ
AP
МТ
МТ
AP
МТ
AP
A