dimanche 10 novembre 2019

How to generate all combinations with replacement variable of array?

I'm trying to generate all possible combinations of an array with undefined as a replacement value.

The values of the array are fixed in place.

So for example we have this array (the array can have a length of x):

const items = [1, 2];

The function that I'm trying to build should generate:

[
 [1, 2],
 [1, undefined],
 [undefined, 2],
 [undefined, undefined]
]



Aucun commentaire:

Enregistrer un commentaire