我很难制定我的问题,我希望你们明白我的意思
有没有办法确保元素永远不会再次结合在一起?
例如,如果A,B,C和D之前已经在同一个新阵列中,那么他们就不应该再次在一起。
这是我的代码,
let xGrps = 3; // Number of groups
let xSize = 4; // Number of items per group
let allItems = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']; // All Items
let newGrps = []; // New groups
for (let i = 0; i < xGrps; i++) {
let tempGrp = "";
for(let j = 0; j < xSize; j++) {
tempGrp += allItems[0] + ",";
allItems.shift();
}
newGrps[i] = tempGrp;
console.log(newGrps[i]);
}
我相信我应该使用这样的东西,
let blockGrps = [{
A: ['B'],
B: ['C','D'],
C: ['E'],
// and so on
}];