Is this algorithm for partial ordering of sets complete and sound?
It is pleasing to see such a nice algorithm. 

Your algorithm is correct for all inputs except possibly for two corner cases.


For example, if we have
input = [['A', 1], ['B', 2], ['A', 2], ['B', 3]], then your algorithm will not produce the expected A&lt;=B.
For example, if we have input = [['A', 1], ['B', 1], ['A', 1], ['B',1] or input = [['A', 1], ['A', 1], ['B', 1], ['B',1], then your algorithm will not produce the expected A&lt;=B and B&lt;=A.


The issue is not in your algorithm proper but how you define your input and expected result and how you specify the way to sort all endpoints of the intervals. Here is a sample solution.


Require that all input intervals are non-degenerate and different.
When sorting, break ties with the other endpoint. That is, given A=[1,2] and B=[2,3], when ['A', 2] and ['B',2] are compared, we must put the former before the latter since 1 &lt; 3.




By the way, you can just use const item of input instead of const item of input.reverse(). Also, you may use ${closed.slice(l[0][0],l[0][1])} &lt;= ${l[1]} instead of ${closed.slice(l[0][0],l[0][1])}:${l[1]} since you use "&lt;=" to define the relation. You should get a slightly prettier output.



Last but not least, Code View Stack Exchange should probably be a better place to post this kind of question.