Credit Card checker help

Hello everyone! I am having a it of trouble understanding the credit card checker assignment in the javascript lesson. So far this is all that I have and even then I am unsure of what I am doing. Would anyone have any advice?

const validateCred = array => {
let newArray =
let reversedNumbers = […array].reverse();
let everyOtherNum = array.filter((element, index) =>{
return index % 2 === 0;
for (let i = 0; i < batch.length; i++){}

I have got a way to reverse my array but that is all I fell confidante about. Would anyone like to connect with me on Discord or through forms to assist me with this project?

You seem to have a mistake in your code:
you have

  let everyOtherNum = array.filter((element, index) =>{
    return index % 2 === 0;

but you should be dealing with the reversed array here, so array in that code should be reversedNumbers .

You could keep going with array methods, for example, using .map

  let doubledEveryOtherNum = => x * 2);
  let modifiedEveryOtherNum = => (x > 9) ? (x - 9) : x );
  let remainingNum = reversedNumbers.filter((element, index) => (index % 2 === 1) );

and then you’d need the sum of every element in modifiedEveryOtherNum and the sum of every element in remainingNum.

The code for testing every card in the batch should not be inside this function, it should be outside it.

I am having a bit of trouble understanding your response. I have been working on the project for a good portion and I came across something. Not completely disregarding my last code but I figured out a way to reverse the cards in batch and get them to be reversed:

const batch = [valid1, valid2, valid3, valid4, valid5, invalid1, invalid2, invalid3, invalid4, invalid5, mystery1, mystery2, mystery3, mystery4, mystery5];

for (const cards of batch) {

This will give me the batch array numbers and in reverse order, The only problem I am running into is inserting this into a function. Is this possible? My thought process is the get the numbers out of the batch array, reverse them then continue to figure out the code.

I’d also recommend creating a copy of the array in your function and then reversing it, so that you don’t change the original array. (Hint: you may be using these arrays for something else in the project)

So I think that reversing the arrays or otherwise changing the original arrays in batch is not a good idea.
I think writing a function (that will be applied to each array in batch, one at a time,) that only deals with one array is a better approach.

const validateCred = array => {
  let newArray = Array.from(array); // copy the array
  newArray.reverse(); // reverses the new array

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