Correctly compare relations with shared origin.

The previous implementation did not handle comparing relation sets that shared one endpoint, but not the other. If either endpoint was shared, the comparison function returned true, that the relations were the same. Now it will check to make sure that both endpoints, instead of just one, are shared.
Yeah, it's a JS idiom. The "normal" approach means JS has to re-calc array length each time through the loop, where as the construction used above means it's only calculated once and then stored in a var.