I was trying to write a algorithm in javascript that returns all the possible 3 digit numbers numbers from a given array of length 6 For Example
(我试图用JavaScript编写一种算法,该算法从长度为6的给定数组返回所有可能的3位数字。)
var arr = [1, 2, 3, 4, 5, 6];
I have already got the combinations with the same sets of numbers in different positions in the 2D array.
(我已经在2D数组中的不同位置获得了具有相同数字集的组合。)
( The code which I took the help of )(( 我帮助的代码 ))
If I have the same numbers in different combinations then I would like to remove them form the array.
(如果我在不同组合中具有相同的数字,那么我想从数组中删除它们。)
like I have [1, 2, 3]
at index i
in the array comtaining all the possible combinations then I would like to remove other combination with the same numbers like [2, 1, 3]
, [1, 3, 2]
and so on..(就像我在包含所有可能组合的数组的索引i
处具有[1, 2, 3]
一样,那么我想删除具有相同数字的其他组合,例如[2, 1, 3]
2、1、3 [2, 1, 3]
, [1, 3, 2]
和等等..)
Note the array also contains numbers repeated like [3, 3, 3]
, [2, 2, 2]
, [3, 2, 3]
and so on
(请注意,数组还包含重复的数字,例如[3, 3, 3]
, [2, 2, 2]
, [3, 2, 3]
,依此类推)
I expect an 2d array
which has the values : [[1,2,3],[1,2,4],[1,2,5],[1,2,6],[1,3,4]]
and so on (24 possibilities)
(我期望一个2d array
,其值是: [[1,2,3],[1,2,4],[1,2,5],[1,2,6],[1,3,4]]
等(24种可能性))
Is there any way to do this?
(有什么办法吗?)
Thank you!(谢谢!)
ask by Karan Gandhi translate from so