【发布时间】:2020-02-19 08:37:16
【问题描述】:
let input = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
我想要的输出应该是:
output = {
first: [[1,2], [3,4], [5,6], [7,8], [9,10]],
second: [[1,3], [2,4], [5,7], [6,9], [8,10]],
third: [[1,4], [2,3], [5,8], [7,9], [6,10]],
fourth: [[1,5], [2,6], [3,7], [8,9], [4,10]],
fifth: [[1,6], [2,8], [3,5], [4,9], [7,10]],
sixth: [[1,7], [2,9], [3,6], [4,8], [5,10]],
seventh: [[1,8], [2,7], [4,6], [5,9], [3,10]],
eighth: [[1,9], [3,8], [4,5], [6,7], [2,10]],
ninth: [[1,10], [2,5], [3,9], [4,7], [6,8]],
}
我需要在 javascript / typescript / nodejs 中编写一个代码,通过它我可以输入数字范围并获得给定数字的组合**(n-1),我想要要编写的代码可以返回我们**所有可能的组合,并且该组合永远不会与其他组合冲突。
提前致谢。
【问题讨论】:
-
每个可能的都应该是一个元组数组吧?
-
到目前为止你尝试了什么?
-
正好有 100 种可能的组合。为什么你的输出只列出 45?
-
@RobbyCornelissen 能否请您解释一下,如何在不与其他组合冲突的情况下获得 100 种可能的组合
-
@RobbyCornelissen,顺序无关紧要。
标签: javascript node.js typescript