Home > OS >  All possible Combinations for this set of letternumbers
All possible Combinations for this set of letternumbers

Time:11-29

I am asking for help to figure out all possible combinations for these sets A1orA2,B1orB2,C1orC2,D1orD2,E1orE2

I attached a picture that is how I want it. And you can only have 1 or 2 in each combination, not both. EX - A1 or A2

Thank you

Here is the combination i want(https://i.stack.imgur.com/qe93y.jpg)?

CodePudding user response:

I think what you are looking for is binomial coefficient.

CodePudding user response:

Adapting this answer about how to generate coin flips.

We can use the following code

const getCombinations = (a) =>
  a.length <= 0
    ? ['']
    : [...getCombinations(a.slice(1)).map(r => a[0]   '1'   r), ...getCombinations(a.slice(1)).map(r => a[0]   '2'   r)]


const b = ['a','b','c','d','e']
console.log(getCombinations(b))

It takes a array of values and then recursively goes down the "length" of the array branching at each point with a "1" or a "2" and slicing off the front of the array.

  • Related