Is There A Total Order On Javascript Objects?
Solution 1:
Depends on what objects we're considering. If we confine our attention to the class of numbers, then yes, the order will be total. As your example demonstrates, the same can be said of (at least some) strings. But totality doesn't seem to hold generally.
For instance, if you add var h = 5;
to your declarations and then add h
to your thereIsTotalOrder
call, you will get a false
. That's because in a state where h = 5
and c = 'foo'
, (h
≤ c
∨ c
≤ h
) is false (which means that totality is not satisfied).
As you rightly noted, while the absence of a false value returned by thereIsTotalOrder
doesn't prove that all objects are totally ordered, the presence of a false
value does prove that the order (if defined) between all objects is not total.
Post a Comment for "Is There A Total Order On Javascript Objects?"