Skip to main content

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:

Typea ? bComment
Numbera == b ? 0 : (a > b ? 1 : -1)
Stringa == b ? 0 : a.compareTo(b)lexicographic comparison
Booleana == 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
Arraya.length == b.length ? 0 : (a.length > b.length ? 1 : -1)Compares number of elements in array
Null / Types are not the sameNot 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.