Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Javascript making combinations with an array

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!