如何获取数组的所有可能组合,但只有某些元素只会更改(在JavaScript中)

发布于 2025-01-23 10:35:36 字数 327 浏览 2 评论 0原文

嗨,有人可以帮我吗?我希望能够生成数组的所有可能组合,但是只有某些元素将更改给定两个可能的数字可供选择。他们的位置也很重要。

例如:令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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文