乘风破浪 激流勇进
你好!欢迎来看Tuziki !

算法——简单洗牌


// 生成52个长度的数组
const cards = Array.from({
		length: 52
	}).map((_, index) => index + 1);
// 从52张排中随机抽取一张,从排队中移除,下次从51中中抽,直到抽完
for (let i = 0; i < 52; i++) {
	const index = Math.floor(Math.random() * 52);
	const [card] =cards.splice(index, 1);
	cards.push(card)
}
console.log(cards) ///
标签:算法
返回列表
返回顶部←