Given an array of paired integers, HOW can I group by intersections. Does anyone have a simple function that could convert my input, into the desired output?
Input
var in = ["0:3", "1:3", "4:5", "5:6", "6:8"]
Desired output
[
[0, 1, 3],
[4, 5, 6, 8]
]
UPDATE:
@apsiller asked my question in the comments more clearly then I originally posted:
"Considering each number as a node in a graph, and each pairing x:y
as an edge between nodes x
and y
, find the sets of numbers that can be traveled to using the edges defined. That is, in graph theory terms, find the distinct connected components within such a graph.
For instance, there is no way to travel from 4 to 0 so they are in different groups, but there is a way to travel from 1 to 0 (by way of 3) so they are in the same group."
To reiterate the desired output is a grouping of transversable nodes, based on a potentially random input set.