Credit Card Checker - findInvalidCards

Hello, in the Credit Card Checker project, I am stuck in step 4 which is: Create another function, findInvalidCards() that has one parameter for a nested array of credit card numbers. The role of findInvalidCards() is to check through the nested array for which numbers are invalid, and return another nested array of invalid cards.

My issue is that when I push the invalid cards from the nested array into my new one (invalidCards), it alters the card number from the original. For example, in the exercise, invalid1 is [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5]. My returned array gives me the value of [8, 5, 6, 2, 5, 7, 7, 7, 5, 1, 0, 9, 2, 7, 9, 5] which I assume is done by my validateCred function.

My code is provided below, and I’m wondering how do I return the unaltered values and if I will have to alter the first function (validateCred)

function validateCred(arr) {
    let sum = 0, even = false;
    for(let i = arr.length - 1; i >= 0; i--){
        if (even && (arr[i] *= 2) > 9) arr[i] -= 9;
        sum += arr[i];
        even = !even;
    }
    if (sum % 10 === 0){
        return true; 
    } else {
        return false;
    }
}

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

console.log(findInvalidCards(batch));
//console.log(invalid1);

I was mutating the array, I missed that part earlier, I fixed it now.

Hey! I’m on it now! Did the first sum result 80 ?

The sum of invalid1 is 85.

Yes perfect!!! Thank you!