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

129
Visualizações
To make possible cartesian combination from the array

I am trying to make possible cartesian combination from an array of arrays but got stuck at one point. I have an array something like this:

0: ['Blue']
1: ['Small']

    var result = values.reduce((a, b) => a.reduce((r, v) => r.concat(b.map(w => [].concat(v, w))), []));
    var cartesianProduct = result.map(a => a.join('-'));

with the help of map reduce I am getting the result as: 0: "Blue-Small" which is not wrong. but what I want is something like this:

0: ['Blue-Small']
1: ['Small-Blue']

and it should be dynamic. It means if I have an array something like this:

0: ['Blue']
1: ['Small']
2: ['New']

then it should return something like this:

0: ['Blue-Small-New']
1: ['Small-Blue-New']
2: ['New-Small-Blue']
3: ['Blue-New-Small']
4: ['Small-New-Blue']
5: ['New-Blue-Small']

How is it possible to get the result like this

about 4 years ago · Juan Pablo Isaza
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