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

214
Views
How to Find the Unique Combination of a List of Permutations in Javascript

Let's say I have an array of permutations.

var D = [["A","B","C"],["A","C","B"],["B","A","C"],["B","C","A"],["C","A","B"],["C","B","A"]]

I want to do the opposite of listing all permutations of a combination. I want to find the unique combination of the permutations using javascript.

That unique combination would be

unique = [["A","B","C"]]

This is just a simple example. I want to find the unique combinations of a larger set of permutations with more elements, but I believe the solution would be scalable.

How do I find the unique combination using javascript?

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

0

This may be a solution:

var D = [["A","B","C"],["A","C","B"],["B","A","C"],["B","C","A"],["C","A","B"],["C","B","A"]];

const unique = [...new Map(D.map(i => [i.sort().join(''), i])).values()];

console.log(unique);

about 4 years ago · Juan Pablo Isaza Report

0

I'm a little unclear what you're asking, but I think it's that you want to find each symbol that occurs in the original list? Will every array within the original list contain the same characters (ie. all sub-arrays in var D will only be made up of "A", "B", and "C")? If so, you could loop through your D array and keep track of each element you see in a Set, which will automatically de-dupe your output for you:

var D = [["A","B","C"],["A","C","B"],["B","A","C"],["B","C","A"],["C","A","B"],["C","B","A"]]
const uniques = new Set()

for(const arr of D) {
    for(const c of arr)  {
        uniques.add(c)
    }
}

console.log(uniques) // -> Set(3) {'A', 'B', 'C'}

Then, if that specific output format is needed, you can convert the set with something like

const arr = []
for(const c of uniques) {
    arr.push(c)
}
const result = [ arr ]
console.log(result) // -> [['A', 'B', 'C']]
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!