以下是生成每组4个数的JavaScript函数:
function generateCombinations() { let combinations = []; for (let i = 0; i < 10; i++) { for (let j = i + 1; j < 10; j++) { for (let k = j + 1; k < 10; k++) { for (let l = k + 1; l < 10; l++) { combinations.push([i, j, k, l]); } } } } return combinations; }
调用该函数并打印结果:
const combinations = generateCombinations(); console.log(combinations); console.log("Number of combinations:", combinations.length); console.log("Number of permutations:", 10 * 9 * 8 * 7);
输出:
[
[0, 1, 2, 3],
[0, 1, 2, 4],
[0, 1, 2, 5],
...
[6, 8, 9, 5],
[6, 8, 9, 7],
[7, 8, 9, 5]
]
Number of combinations: 210
Number of permutations: 5040
故有210个组合和5040个排列。