But still this is as far as I know this is the best way to sort a field using only geometry nodes and no programming. So as stated in the question I wanted to connect two random sets of point based on their distance from an empty (picture 1). But the same approach should work for sorting any field.
Now for the interesting nodes, the "sort list" node takes the count (len of field), any unsorted field and a resolution count. And itIt outputs a debug geometry, the sorted list and a list of ids (index of each value for unsorted field, look at the next few pictures).
The main idea is placing the original field on a line, and then merge a "sorted" (i.e. normal mesh line) by distance to the field vertices. Lastly it returningreturns the vertex positions as a sorted field. (Excuse my poor drawing, but it shows the idea of how the node works):
So next problem, Blender nodes have no loop function, but they do have field math and field logic. And we know that all "single pass" nested loops (with no exit logic) can be translated into a single loop of n^2 iterations:


