I want to generate possible pairs from string array
this is what I got now:
const findPossiblePair = (array) => {
const results = [];
for (let i = 0; i < array.length - 1; i++) {
for (let j = i + 1; j < array.length; j++) {
results.push(`${array[i]}-${array[j]}`);
}
}
return results;
};
const result = findPossiblePair(['michael', 'john', 'annie'])
console.log(result)
currently it generates: ["michael-john", "michael-annie", "john-annie"]
I want it to be: ["michael-john", "john-michael", "michael-annie", "annie-michael"]
notice michael becomes some sort of "anchor" because it's there in all of the elements
e.g.
if the anchor is "annie", it generates: ["annie-michael", "michael-annie", "annie-john", "john-annie"]
I believe I need to add a parameter on the function for the anchor
but I'm in complete stuck
please help me