Hi all. I have an issue with the card checker project and I don’t know why… I’ve tried every single thing to figure it out and I just can’t. Maybe someone can give me some advice?
Essentially my code for doing the Luhn Algorithm is below. It seems to work and pick up every invalid number, EXCEPT Valid No 3… It somehow manages to slip through the cracks…
Can i get some help please?
const validateCred = (array) => {
let arraySum = [];
for (let i = 15; i >= 0; i--) {
if (i%2 !== 0) {
arraySum.push(array[i]) } else {
if ((array[i] * 2) > 9) {
arraySum.push((array[i] * 2) - 9);
} else {
arraySum.push((array[i] * 2));
};
};
};
const initialValue = 0;
const sumSum = arraySum.reduce((accumulator, currentValue) => accumulator + currentValue, initialValue);
if (sumSum % 10 === 0) {
return true;
} else {
return false;
};
};