Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda