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
// intscompare(1, 4) // -1compare(1, 4) // 0compare(4, 1) // +1 // floatscompare(1.0, 4.0) // -1compare(1.0, 4.0) // 0compare(4.0, 1.0) // +1 // stringscompare("apple", "banana") // -1compare("apple", "apple") // 0compare("banana", "apple") // +1