274 - Integers Comparator #348
Labels
274
answer
Share answers/solutions to a question
en
in English
recommended
Answers / solutions that provided by the official team or the original author
Solution
TypeScript playground
The solution creates some custom digits that will be used for digit-by-digit comparison, and then, converts numbers to string literal types, comparing them digit-by-digit afterward.
There are additional early checks for number equality.
In case one number is negative and the other is positive, the result can be quickly concluded too.
In case both numbers are negative, the result is the inverse of the result for the reversed absolute arguments (
compare(-5, -8)
is the same ascompare(8, 5)
)The solution contains tests for each written type.
Test cases
They are the same as in the challenge
The text was updated successfully, but these errors were encountered: