Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Luhn #17

Merged
merged 3 commits into from
Aug 28, 2024
Merged

Luhn #17

merged 3 commits into from
Aug 28, 2024

Conversation

adnilsson
Copy link
Owner

@adnilsson adnilsson commented Aug 28, 2024

Description

Solutions to the Luhn exercise.

Mentoring

First iteration

I'm happy that I managed to write the digits computation without branches. The mentor had some additional tips, however.

Regarding the return expression on :

To me, you could just write checksum % 10 == 0 and that would be perfectly fine
This is a valid point, which is amended in the second iteration.

Also:

chars() is an iterator, so you don't need to convert it into an iterator

Moreover, I became aware of the let-else syntax.

second iteration

The discussion with the mentor ended without further comments.

* chars().into_iterator() is unnecessary
* so is the second !c.is_ascii_whitespace() filter
* simpler return expression with `checksum % 10 == 0`
* let-else is a thing since Rust 1.65
* Boxing is_none in a lambda is not needed. I thought that it was since
is_none takes a &self, which I typically associate  with methods, but
rust seems to be able to figure this out.
@adnilsson adnilsson merged commit ce2391d into main Aug 28, 2024
@adnilsson adnilsson deleted the luhn branch September 5, 2024 18:00
@adnilsson adnilsson mentioned this pull request Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant