Shuffle an array as many as possible

前端 未结 8 1376
一向
一向 2020-12-07 05:21

I have an array like this

[0,2,3]

The possible shuffling of this array are

[0,2,3], [2,3,0], [3,0,2], [3,2,0], [0,3,2],         


        
8条回答
  •  旧时难觅i
    2020-12-07 05:54

    tibos example above was exactly what I was looking for but I had some trouble running it, I made another solution as an npm module:

    var generator = new Permutation([1, 2, 3]);
    while (generator.hasNext()) {
      snippet.log(generator.next());
    }
    
    

    https://www.npmjs.com/package/iterative-permutation

    https://github.com/bcard/iterative-permutation

提交回复
热议问题