"```javascript function shuffleArray(array) { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array; }
function groupDraw(names, groupSize) { const shuffledNames = shuffleArray([...names]); // 随机打乱参与抽签的名字数组 const result = []; while (shuffledNames.length > 0) { const group = shuffledNames.splice(0, groupSize); // 从打乱后的数组中取出一组名字 result.push(group); // 将分组加入结果数组 } return result; }
// 使用示例 const participants = ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'Grace', 'Hannah']; const groupedParticipants = groupDraw(participants, 3); console.log(groupedParticipants);
"