Conversation
| -- DON'T FORGET TO SPECIFY THE TYPE IN HERE | ||
| lastDigit n = error "lastDigit: Not implemented!" | ||
| lastDigit :: Int->Int | ||
| lastDigit n = mod n 10 |
There was a problem hiding this comment.
Your implementation is almost correct š
Unfortunately, it returns negative numbers on negative inputs because of how mod works. Sometimes corner cases can be tricky to spot and fix...
| let last = mod n 10 | ||
| x = div n 10 |
There was a problem hiding this comment.
That is a wonderful solution! šš¼ You correctly noticed that it is the div and mod, cool š
One hint to make your solution even shorter: you can see that you use both:
mod m 10
div m 10The standard library has the divMod function, that actually combines inside both div and mod. And this is exactly what you use!.
So you could write it this way:
(x, y) = divMod m 10You can see how we could pattern match on the pair š
Co-authored-by: Veronika Romashkina <vrom911@gmail.com>
Co-authored-by: Veronika Romashkina <vrom911@gmail.com>
|
Thank you so much for the valuable feedback I have made the necessary changes as per your suggestion |
Solutions for Chapter 1
cc @vrom911 @chshersh