You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调整欧冠2024瑞士制36队对阵数组,实现主客场场次均等

瑞士制欧冠赛事主客场均衡分配问题

我正在搭建包含36支球队的2024欧冠联赛瑞士制赛事,每队需对阵8个不同对手,总计144场比赛。已生成对阵列表,现需调整每组对阵的顺序(数组首位为主队,次位为客队),确保每队均拥有4个主场、4个客场。

我尝试通过判断主队当前主场场次是否超过4场来交换主客队顺序,但结果仍无法实现均等分配。附示例代码:

const matchups = [
    ["35", "36"],
    ["36", "34"],
    ["12", "36"],
    ["36", "28"],
    ["36", "3"],
    ["36", "19"],
    ["36", "16"],
    ["36", "14"],
    ["13", "20"],
    ["12", "13"],
    ["13", "27"],
    ["7", "13"],
    ["1", "13"],
    ["21", "13"],
    ["35", "13"],
    ["13", "15"],
    ["37", "3"],
    ["21", "37"],
    ["54", "37"],
    ["11", "37"],
    ["37", "27"],
    ["1", "37"],
    ["37", "14"],
    ["22", "37"],
    ["15", "17"],
    ["11", "15"],
    ["15", "27"],
    ["1", "15"],
    ["15", "54"],
    ["41", "15"],
    ["40", "15"],
    ["23", "1"],
    ["40", "23"],
    ["25", "23"],
    ["24", "23"],
    ["41", "23"],
    ["23", "3"],
    ["23", "9"],
    ["18", "23"],
    ["41", "27"],
    ["27", "54"],
    ["40", "27"],
    ["27", "18"],
    ["27", "19"],
    ["7", "3"],
    ["33", "3"],
    ["32", "3"],
    ["2", "3"],
    ["3", "54"],
    ["41", "29"],
    ["40", "29"],
    ["29", "28"],
    ["2", "29"],
    ["10", "29"],
    ["26", "29"],
    ["12", "29"],
    ["29", "22"],
    ["25", "34"],
    ["34", "24"],
    ["10", "34"],
    ["34", "16"],
    ["11", "34"],
    ["48", "34"],
    ["34", "17"],
    ["14", "24"],
    ["14", "9"],
    ["33", "14"],
    ["25", "14"],
    ["7", "14"],
    ["14", "17"],
    ["21", "17"],
    ["48", "17"],
    ["32", "17"],
    ["17", "16"],
    ["12", "17"],
    ["28", "1"],
    ["28", "25"],
    ["28", "21"],
    ["28", "43"],
    ["11", "28"],
    ["28", "9"],
    ["54", "12"],
    ["54", "33"],
    ["54", "43"],
    ["54", "25"],
    ["16", "25"],
    ["16", "33"],
    ["16", "43"],
    ["7", "16"],
    ["16", "18"],
    ["19", "24"],
    ["19", "12"],
    ["19", "48"],
    ["11", "19"],
    ["10", "19"],
    ["19", "1"],
    ["2", "43"],
    ["43", "18"],
    ["40", "43"],
    ["7", "43"],
    ["32", "43"],
    ["18", "48"],
    ["18", "10"],
    ["18", "2"],
    ["18", "20"],
    ["25", "7"],
    ["26", "25"],
    ["32", "9"],
    ["9", "48"],
    ["9", "22"],
    ["9", "2"],
    ["9", "10"],
    ["41", "20"],
    ["20", "22"],
    ["20", "21"],
    ["20", "10"],
    ["20", "40"],
    ["20", "32"],
    ["10", "41"],
    ["35", "10"],
    ["22", "33"],
    ["22", "7"],
    ["35", "22"],
    ["22", "32"],
    ["48", "35"],
    ["48", "40"],
    ["48", "41"],
    ["24", "41"],
    ["24", "2"],
    ["24", "21"],
    ["24", "12"],
    ["33", "32"],
    ["33", "11"],
    ["33", "35"],
    ["26", "32"],
    ["21", "7"],
    ["26", "21"],
    ["1", "26"],
    ["1", "35"],
    ["2", "40"],
    ["2", "26"],
    ["35", "26"],
    ["26", "11"],
    ["12", "11"]
];

const totalRounds = 8;

matchups.forEach((matchup) => {
  matchup.sort((homeTeam, awayTeam) => {
      const homeMatch = matchups.filter((m) => m[0] === homeTeam);
      return homeMatch.length > (totalRounds / 2 ) ? 1 : -1;
  });
});

const home = _.groupBy(matchups, m=> m[0]);
const away = _.groupBy(matchups, m=> m[1]);

console.log("home", home);
console.log("away", away);
console.log("combined",_.mergeWith(home,away, ((objValue,srcValue)=>{
   if(Array.isArray(objValue)){
     return objValue.concat(srcValue);
   }
})));

内容的提问来源于stack exchange,提问作者RedGiant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 19:29:49