Credit Card Checker challenge - help with validateCred function

Hi
Would love some feedback.
I’m at the Credit Card Checker challenge.
Been trying it without looking at the hint so went in a different path, however the validateCred() function does not return the correct Boolean.

I tried to do it without reversing the arrays.

this is the code with comments:


const validateCred = array => {
//creating an empty array
  let arrayMod = [];
//pushing the first element from an array to the new array
  arrayMod.push(array[0]);
// pushing the rest of the elements, minding that if its index is odd, it's multiplied by 2 (and then checked if it's greater than 9) 
  for (let i = 1; i < array.length; i++) {
    if (i % 2 !== 0){
      if (array[i] * 2 <= 9){
      arrayMod.push(array[i] * 2)
      } else {
        arrayMod.push(array[i] * 2 - 9)
      }
        } else {
      arrayMod.push(array[i]); 
        }
  }
//up until now consol.log shows correct calculation. next is summing up the arrayMod and checking its modulo:
    let arraySum = arrayMod.reduce ((a,b) => a+b, 0);
    if (arraySum % 10 === 0) {
      return true
    } else {
      return false
    }
  };

console.log(validateCred (valid1));

problem is some of the valid arrays return false and vice versa.
and I cannot find the error.
would love some feedbck on my code.
TIA!

would appreciate the help…
Thanks!

here is a visual outline:

https://codecademy-content.s3.amazonaws.com/PRO/independent-practice-projects/credit-card-checker/diagrams/cc+validator+diagram+1.svg

You didn’t do step 1 correctly:

Starting from the farthest digit to the right, AKA the check digit, iterate to the left.

you start for the left and go to the right, causing the wrong digits to be doubled.

There’s nothing stopping you from observing what your program is doing.

There are some series of steps you should carry out, yes?
Are those steps being carried out? LOOK. Print what you have. Do something. Print out what you’ve got now.

You might want to start with carrying out the steps manually to see if you get the right result yourself.