I am trying to find all combinations and create an array of string from an array. For example:
var text_array = [["h"],["e","è","é","ê","ë"],["l"],["l"],["o","ò","ó","ô","õ"]]
output = ["hello","hèllo","héllo",etc...]
I have tried several ways but they all seemed extremely long winded and I think I'm just maybe missing a function I don't know about.
One way to abstract the implementation from the number of characters is to incrementally build the list of final values and the values themselves. You start with an empty result, [""]. Then you take the first list of variants and add each variant to every result we have so far, producing a new list of intermediate results, ["h"].
The second list of variants has multiple elements, so after this iteration you'll have this list of results, ["he", "hè", "hé", "hê", "hë"]. And so on.
In pseudo-code, it could look like this:
results = [""]
for each list_of_variants in text_array {
new_results = []
for each variant in list_of_variants {
for each result in results {
new_result.push(result + variant)
}
}
results = new_results
}