Credit Card Checker: findInvalidCards()

In my findInvalidCards function output is always coming array with valid and invalid cards i don’t know what’s the problem in my function.

const findInvalidCards = arrList => {

let invalid = ;

for(let x of arrList) {

if(!validateCred(x)) {

  invalid.push(x);

}

}

return invalid;

}

console.log(findInvalidCards(batch));

This is my code : https://gist.github.com/625eec5e003a82c780688a6c3d2a9922

Here:

for(let i = 15; i >= 0; i--) {

I wouldn’t hard-code the length of the array, use arr.length

But the fundamental problem is here:

let sum = 0;

sum is declared outside the function. Which means the numbers of the second card are added to the sum of the first card

the numbers of the third card are added to the sum of first and second card and so forth

This way, it becomes pretty random. We should get the sum of the numbers of each individual credit card. The sum shouldn’t include numbers from other credit cards

thanks i got the answer.