Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda