DSA icon indicating copy to clipboard operation
DSA copied to clipboard

Return all the possible permutations of x elements in a given array of size n in Javascript (recursive version - replicates optional)

Open ghost opened this issue 2 years ago • 4 comments

Information about Algorithm

The algorithm returns an array of all the possible permutations (not combinations because order matters here) of x elements (x being one of the algorithm's parameters) in any given array of size n. For instance, if the input array is [1,2,3,4,5] and x = 2, the return would start like this: [[1,1],[1,2],[1,3]...] The algorithm uses a recursive approach and enables the inclusion or the exclusion of replicates through a boolean argument). In other words, the algorithm has three parameters: an input array of length n, the number of elements per permutation called x and a boolean value (true = replicates accepted and false = replicates excluded). It returns an array of all the possible permutations. For instance, allPermutations([1,2,3,4,5], 2, false) would return something that would start with [[1,2],[1,3],[1,4]...]

Have you read the Contributing.md and Code of conduct

  • [X] Yes
  • [ ] No

Other context

This is a common problem for people dealing with probabilities (and statistics more generally). It is also a recurring problem on competitive platforms.

ghost avatar Mar 04 '22 01:03 ghost

Thanks for opening your first issue here! Be sure to follow the issue template!

welcome[bot] avatar Mar 04 '22 01:03 welcome[bot]

Hi @supaamucho, I will wait for your pull request.

ming-tsai avatar Mar 04 '22 14:03 ming-tsai

Hi @ming-tsai , I'm interested in tackling this issue if no one is working on it.

KYu-2468 avatar Dec 17 '22 08:12 KYu-2468

Hi @supaamucho, Are you working on this?

ming-tsai avatar Dec 21 '22 12:12 ming-tsai