Skip to content
Advertisement

Get all permutations of bool array

I need all permutations of a bool array, the following code is inefficient, but does what I want:

JavaScript

However it is inefficient and fails for long arrays. Is there a more efficent implementation?

Advertisement

Answer

What about sampling the combinations of indices of the True values:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement