 # Suggestion about the CreditCard Checker project

I finally encountered this exercise I was reading so much in the Get Help section of the forum, some feedback about it:

At step 3 when it states:

The calculations in the Luhn algorithm can be broken down as the following steps:

1. Starting from the farthest digit to the right, AKA the check digit, iterate to the left.
2. As you iterate to the left, every other digit is doubled (the check digit is not doubled). If the number is greater than `9` after doubling, subtract `9` from its value.

I suggest to change it with:

The calculations in the Luhn algorithm can be broken down as the following steps:

1. Either reverse the array and iterate normally from left to right or do not reverse the array but iterate from the right to the left.
2. If the length of the original array is an odd number double the value of each digit that is positioned at an odd index, otherwise if the length of the original array is an even number, double the value of each digit that is positioned at an even index.
3. If the number doubled is greater than `9`, subtract `9` from its value.

Reason:
I find that the sentence “every other digit” can be easily misinterpreted, as by that it can be meant either the series of odd numbers or even numbers. So which to choose?
Well the purpose is to exclude the series that contain the last digit (Check Digit), however what is written in parenthesis: “check digit is not doubled” imo does not address that. In fact, a possible confusing scenario is to double the series of numbers the check digit is part of, but not the check digit itself (check digit is not doubled indeed).
It’s true however that there’s the diagram linked at the end of the step which makes it very clear, if only a student would just click and open it. Also, at step 7 when it states:

If you’d like to challenge yourself further, you could consider the following:

The link indicated shows a table with the real conditions to use to verify if a card number is valid or not, however I have reason to suspect that some of those (VISA, VISA Electron, Maestro) are incorrect/incomplete. Maybe change it with a different link?

Cheers,

I can confirm that I had a hard time understanding the Luhn algorithm from the description as well. The graph made it perfectly clear to me, but I had the impression that it contradicts the description. But that seemed to be caused by not knowing that “every other” means every second, or omitting one digit rather than “every other than the check digit”. But what can you do when people just don’t speak proper English And I appreciate improving all language skills here I wouldn’t go too much into details with the description of the task though. Because with the suggestion you made here, it would become more difficult to come up with this beautiful solution posted by @mtf :

``````const luhn = t => {
const g = (a, b) => +a + +b
const f = x => [...(x.toString())].reduce(g)
const s = t.slice()
for (let n = s.length % 2; n < s.length; n += 2) {
s[n] = f(s[n] * 2)
}
return s.reduce(g) % 10 == 0
}
``````
1 Like

I wouldn’t go too much into details with the description of the task though.

I thought about that, you’re right. But still, I think that some modification, even if not the one I suggested , could be made. with this beautiful solution posted by @mtf

I missed that post, can you share the link? Should I post also mine? 1 Like

Let’s see what answers you get to your question about cheating 