Hi guys,
I got stuck on the Credit Card Checker Project:
https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-challenge-project-credit-card-checker/projects/credit-card-checker
Here is my code: https://gist.github.com/michaelarie96/eea621f3d4a976809a2a8b95e58b0216
Every thing seems ok with my code, I checked it thoroughly, but for some reason the function validateCred
is mutating the parameter array which is called with the function, even though it’s not used or returned in the end:
const validateCred = arr => {
const checkedArray = arr;
for (let i = checkedArray.length - 2; i >= 0; i -= 2) {
checkedArray[i] *= 2;
if (checkedArray[i] > 9) {
checkedArray[i] -= 9;
}
}
const checkedNumber = checkedArray.reduce((acc, currValue) => acc + currValue);
if (checkedNumber % 10 === 0) {
return true;
} else {
return false;
}
}
You can see in the original code that I checked the array with a console.log
on line 46 (before the function is called) and on line 52 (after the function was called), and the array is unfortunately mutated.
Any guidance would be appreciated. Thanks