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

127
Views
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
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!