Browse Source

docs(luhn-algorithm): clarify input handling and steps in the example

pull/2228/head
Michele Sessa 7 months ago committed by Michele
parent
commit
0d7db91ec0
  1. 7
      subjects/luhn_algorithm/README.md

7
subjects/luhn_algorithm/README.md

@ -5,8 +5,9 @@
Create a function which checks if a number is valid per the Luhn formula.
The function will receive a string and return a boolean.
An empty string or a number with only one digit will be considered an invalid number.
Spaces are accepted in the script but have to be stripped during the calculation (in other words they won't affect the result).
**Invalid inputs:** An empty string or a number with only one digit are considered invalid.
**Handling spaces:** Spaces are accepted but have to be ignored during the calculation (in other words they won't affect the result).
The Luhn formula is used to check if a number is a valid credit card number and in some other scenarios where you need to check a number fast and without accessing a database.
@ -23,7 +24,7 @@ So we will get:
- `4539 3195 0343 6467`
- `4_3_ 3_9_ 0_4_ 6_6_`: numbers to modify
- `8_6_ 6_9_ 0_8_ 3_3_`: modified numbers
- `8_6_ 6_9_ 0_8_ 3_3_`: modified numbers (for numbers over 9 we subtracted 9 already)
- `8569 6195 0383 3437`: the new sequence of digits
- `80`: the sum of all digits
- `80` is evenly divisible by 10 so the result is `true`

Loading…
Cancel
Save