Sentinel
Builtin Function: compare
compare(value1, value2)
The built-in function compare
compares two values. The only valid types that
can be provided are integers, floats or strings. Strings are compared according
to lexicographic ordering; which is comparable to alphabetical
ordering, but also takes into account symbols.
The following table provides an overview of the possible return values:
Result | Description |
---|---|
-1 | value1 is less than value2 |
0 | value1 is equal to value2 |
+1 | value1 is greater than value2 |
Examples
// ints
compare(1, 4) // -1
compare(1, 4) // 0
compare(4, 1) // +1
// floats
compare(1.0, 4.0) // -1
compare(1.0, 4.0) // 0
compare(4.0, 1.0) // +1
// strings
compare("apple", "banana") // -1
compare("apple", "apple") // 0
compare("banana", "apple") // +1