0

I'm a newbie and trying to create a function in JavaScript that given a string and the number of draws and will return an array of all possible combinations of the letters.

Eg. the urn contains of 3 balls (A B C) and 3 draws should return

fun (ABC, 3) -> AAA, AAB, AAC, ABA, ..... CCC

As well as:

fun(A, 2) -> A A

fun(AB,2) -> AA, AB, BA, BB

And also in case of (A B C) and 2 draws the fun() should return

fun(ABC, 2) -> AA, AB, AC, BA, BB, ....

Do you have any idea ?

Thanks.

dude
  • 1
  • Welcome to Stack Overflow. Please read [How to ask a good question](https://stackoverflow.com/help/how-to-ask) – Sven 31415 May 30 '18 at 18:45
  • 1
    This should get you started: [Permutations in JavaScript?](https://stackoverflow.com/questions/9960908/permutations-in-javascript) – Felix Kling May 30 '18 at 18:50
  • A little search gets me an ES5 answer [here](https://rosettacode.org/wiki/Permutations_with_repetitions#ES5) and ES6 [here](https://rosettacode.org/wiki/Permutations_with_repetitions#ES6) – HMR May 30 '18 at 20:35
  • Thanks! Do you know some code for the solution of The Mississippi Counting Problems? – dude May 31 '18 at 07:27

0 Answers0