Weird Error - Credit card checker

Can someone help me with step 4 of the exercise?
I don’t know why, but when I call the function and log the array with invalid credit cards, it shows the following arrays (which do not correspond to any credit card number):

[ [ 5, 9, 7, 2, 9, 0, 1, 5, 7, 7, 7, 5, 2, 6, 5, 8 ],
[ 3, 8, 6, 8, 3, 2, 2, 9, 3, 6, 9, 1, 5, 9, 7, 1 ],
[ 4, 2, 9, 9, 5, 8, 4, 7, 0, 3, 9, 5, 5, 5, 3 ],
[ 5, 6, 9, 5, 7, 5, 1, 3, 9, 5, 2, 2, 1, 2, 0, 3 ],
[ 4, 1, 8, 6, 8, 7, 2, 5, 7, 9, 1, 0, 2, 7, 3, 1 ],
[ 4, 2, 4, 1, 0, 6, 8, 3, 9, 2, 0, 7, 4, 8, 3 ],
[ 3, 0, 2, 3, 5, 3, 2, 3, 9, 0, 2, 0, 7, 5, 3, 2, 1, 0, 6 ],
[ 3, 9, 0, 5, 1, 4, 9, 3, 1, 5, 7, 7, 9, 4, 9, 8 ] ]

Then you’d look at where you are changing them

I suppose it’s somewhere around here:
let invalidCards =

function findInvalidCards(batchArr) {
for (let i =0; i < batchArr.length; i++) {
if (validateCred(batchArr[i]) === false) {
invalidCards.push(batchArr[i]);
}
}
};

But I have no idea how it happened…

You can print things out to observe what is happening
…just don’t forget to keep in mind what you mean should be happening

I figured out my error: I ended up mutating the values of the original arrays. I fixed that by adding the .slice() method in my newArr variable.
Thank you for your help.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.