Hi there… thank you… here is my code below:
// An array of all the arrays above
const batch = [valid1, valid2, valid3, valid4, valid5, invalid1, invalid2, invalid3, invalid4, invalid5, mystery1, mystery2, mystery3, mystery4, mystery5];
// Add your functions below:
const validCred = (array32) => {
let sum1 = ;
let sum2 = ;
for (let i = array32.length-2; i>=0; i-=2) {
sum1.push(array32[i]);
} // array list of every other number starting from the end not including the first check digit
for (let i = array32.length-1; i>=0; i-=2) {
sum2.push(array32[i]);
} //array list of every odd number starting from the end
const double = sum1.map(x =>
x*2); // multiplying the even number array by two
const double2 = double // chaining iterator methods
.filter(n => n > 9) //filtering numbers above 9
.map(n => n - 9); // subtracting 9 from those numbers
// console.log(double2);
const double3 = double // filtering all the numbers less than 9
.filter(n=> n <=9);
// console.log(double3);
const finalSum1 = double2.concat(double3); // joining the two arrays togethor of the even numbers togethor
// console.log(finalSum1);
const finalSumAll = finalSum1.concat(sum2);
// console.log(finalSumAll);
const sumTotal = finalSumAll.reduce(function(accumulator, currentValue) {
return accumulator + currentValue;
}, 0);
// console.log(sumTotal);
finalAns = sumTotal % 10;
return finalAns;
}
const findInvalidCards = (array21) => {
let invalidCards = ;
let validCards = ;
for (let i=0; i<=array21.length-1; i++){
let check = validCred(array21[i]);
if (check === 0) {
validCards.push(array21[i]);
} else {
invalidCards.push(array21[i]);
}
}
// return validCards;
return invalidCards;
}
function idInvalidCardCompanies(invalidBatch) {
for (let i = 0; i <= invalidBatch.length; i++) {
console.log(invalidBatch[i][0]);
if (invalidBatch[i][0] === 3) {
console.log(‘Amex’);
} else if (invalidBatch[i][0] === 4){
console.log(‘Visa’);
} else if (invalidBatch[i][0] === 5){
console.log(‘Mastercard’);
} else if (invalidBatch[i][0] === 6){
console.log(‘Discover’);
} else { console.log(‘Company not found’);
}
}
}
console.log(findInvalidCards(batch));
idInvalidCardCompanies(findInvalidCards(batch));