Comparison logic
Some functions use comparison for evaluation (e.g. $$sort
& $$is
).
The following table will explain what is the expected result for each comparison of 2 values:
Type | a ? b | Comment |
---|---|---|
Number | a == b ? 0 : (a > b ? 1 : -1) | |
String | a == b ? 0 : a.compareTo(b) | lexicographic comparison |
Boolean | a == b ? 0 : (a ? 1 : -1) | true > false |
Object | #keys(a) == #keys(b) ? 0 : (#keys(a) > #keys(b) ? 1 : -1) | Compares number of keys in object |
Array | a.length == b.length ? 0 : (a.length > b.length ? 1 : -1) | Compares number of elements in array |
Null / Types are not the same | Not comparable * |
note
Not comparable values behave different in context, $$sort
will treat both values as equal, while $$is
will return false
for any 2 values.