如何获取数组的所有可能组合,但只有某些元素只会更改(在JavaScript中)
嗨,有人可以帮我吗?我希望能够生成数组的所有可能组合,但是只有某些元素将更改给定两个可能的数字可供选择。他们的位置也很重要。
例如:令ARR = [1,2,3,(4或5),(6或7),(8或9)]
我想生成
1,2,3,4,6,8
1,2,3,4,6,9
1,2,3,4,7,8
。
。
。
。
这一直持续到1,2,3,5,7,9
我知道它与二进制数字非常相似,我只是不知道该如何处理,而且数组的大小可能会改变,因此可以导致一个很多选择和可能的结果。
请。有人帮忙。
编辑:澄清我要生成的组合
Hi can anyone please help me. I want to be able to generate all possible combinations of the array but only certain elements will be changing given two possible numbers to choose from. Their position is important too.
For example: let arr = [1,2,3, (4 or 5), (6 or 7), (8 or 9)]
I want to generate
1,2,3,4,6,8
1,2,3,4,6,9
1,2,3,4,7,8
.
.
.
.
This goes on until 1,2,3,5,7,9
I know it is very similar to binary numbers, I just don't know how to go about it and also the array may change in size so it can lead to a lot of options and possible outcomes.
Please. Someone help.
Edit: clarified the combinations I want to generate
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论