L
L
lunaxoddd2020-08-02 10:27:49
JavaScript
lunaxoddd, 2020-08-02 10:27:49

Combinatorics in Java Script, how to add a dot in all possible combinations of an array?

you need to make sure that when you enter a string, a dot is put in all possible combinations, including two dots

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2020-08-02
@lunaxoddd

Make a recursive function that solves your problem. If the character at the input is 1 - just return it. If there are several input characters, then it bites off the last character and is called recursively, then appends the last character and the point-last character (a new array with twice the number of elements) to each element of the returned array.
So for 3 characters "abc" the function for "ab" will be called, which will return [ab, ab], adding "c" and ".c" to each element we get [abc, ab.c, a.bc, abc] .

X
xmoonlight, 2020-08-02
@xmoonlight

Concatenation (thinning) with a bit "mask".
ABC - string
M1, M2 - two-bit "mask"
Glue in a loop: A+M1+B+M2+C

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question