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

124
Views
Challenge on mapping on Array of Arrays

I'm working on a data manipulation project - where I have to map through an array of arrays and export a single string of all possibilities within these arrays.

For example:

const array = [
    [{id: 1}, {id: 2}], [{id: "a"}, {id: "b"}], [{id: "string"}]
]

Expected output is to have:

const newArray = ["1_a_string", "2_a_string", "1_b_string", "2_b_string"]

I'm having challenges in having all permutations knowing:

  1. I don't know the lenght of initial array
  2. I don't know the lenght of the array inside the initial array.

Appreciate if anyone can guide me to the right path to solve it.

Thanks

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

0

you can write a function like this and you can manipulate this function as your requirement . that means if you want concated string something like that..

function print(arr)
{
    let n = arr.length;
     
    let indices = new Array(n);
   
    for(let i = 0; i < n; i++)
        indices[i] = 0;
     
    while (true)
    {
        for(let i = 0; i < n; i++)
            document.write(
            arr[i][indices[i]].id + " ");
          
        document.write("<br>");
        let next = n - 1;
        while (next >= 0 && (indices[next] + 1 >=
                                 arr[next].length))
            next--;
         
        if (next < 0)
            return;
         
        indices[next]++;
         
        for(let i = next + 1; i < n; i++)
            indices[i] = 0;
    }
}
 
// Driver code
 

const array = [
    [{id: 1}, {id: 2}], [{id: "a"}, {id: "b"}], [{id: "string"}]
]

 
print(array);

Here is codepan link

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!