I need help on how to reverse a Integer
in Haskell with the following type signature:
reverseInt :: Integer -> Integer
reverseInt a = undefined -- help here
I need the Integer
input number to be reversed like the example below.
Example:
> reverseInt 1989
9891
reverseInt :: Integer -> Integer
reverseInt = read . reverse . show
This does not address negative numbers. If you need to reverse negative numbers, you can simply use
reverseInt :: Integer -> Integer
reverseInt x = (*) (signum x) . read . reverse . show . abs $ x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With