I want to create a list of pairs for all possible connections given a list of ids efficiently since these are large lists. Every id should be connected only once and never to itself. They only need to obey the formula n (n - 1) / 2 for connections.
const ids = [1,2,3,4]
const pairs = [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
// My first attempt was nested for loops
let pairs = []
for (let i = 0; i < array.length; i++) {
let pair
for (let j = i + 1; j < array.length; j++) {
pair = [array[i], array[j]]
pairs = [...pairs, pair]
}
}