MakeContributions / DSA

Data Structure and Algorithm (DSA) contributions
MIT License
732 stars 772 forks source link

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

Open ghost opened 2 years ago

ghost commented 2 years ago

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

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.

welcome[bot] commented 2 years ago

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

ming-tsai commented 2 years ago

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

KYu-2468 commented 1 year ago

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

ming-tsai commented 1 year ago

Hi @supaamucho, Are you working on this?