tl;dw (too lazy, didn't write): thought of it right before I fell asleep
Breaking a number is defined as the following steps:
- Take a number or a parseable data type as input in any allowed way.
- Duplicate the first digit (64 -> 664)
- Subtract 4 from the last digit (664 -> 660)
- If the subtraction gets a negative last digit, move the negative sign (-) to the front of the number (73 -> 773 -> -771)
- If the original number was negative, and the last digit becomes negative, remove all negative signs entirely. (-44441 -> 444443)
- Output the number in any allowed way.
Here are a few test cases:
64 -> 660 73 -> -771 thisisnotanumber -> (handle the situation) 432188 -> 4432184 -83213 -> 883211 (two negative signs turn into a positive) 0 -> -4 (0 -> 00 -> 0-4 -> -04 -> -4)
By "parseable data type", I mean any data type (String, Float, etc) that can be converted into the number type your program/function uses (Integer, Number, etc).
Your answer can be a function or a program. In both cases, provide an explanation of the code.
If it is a function, give a usage of it.
Test cases (or online interpreter) would be a nice plus to your answer.
Preceding 0s (-04) aren't allowed.
Behavior should be exactly replicated from the test cases above.