Credit Card Checker Challenge Project (JavaScript)

This is my solution to this challenge

Really good challenge for sure. Here’s my solution:

// Step #3 function validateCred(array) { let revArray = array.reverse(); let cardCheck = []; let cardSum = 0; for (num in revArray) { if (num % 2 == true) { let revArrayDub = revArray[num] * 2; if (revArrayDub > 9) { cardCheck.push(revArrayDub - 9); cardSum += (revArrayDub - 9); } else { cardCheck.push(revArrayDub); cardSum += revArrayDub; }; } else { cardCheck.push(revArray[num]); cardSum += revArray[num]; }; }; //console.log(`Card Check: ${cardCheck}`); //console.log(`Card sum: ${cardSum}`); if (cardSum % 10 === 0) { return 'Credit card number is valid!'; } else { return 'Credit card number is NOT valid!'; }; }; //console.log(validateCred(mystery5)); // Step #4 function findInvalidCards(array) { let invalidCards = []; let nestedBatch = batch.forEach((card) => { if (validateCred(card) === 'Credit card number is NOT valid!') { invalidCards.push(card.reverse()) }; }); return invalidCards; }; //console.log(findInvalidCards(batch)); // Step #5 function idInvalidCardCompanies(array) { let cardNums = findInvalidCards(array); let invalidCompanies = []; for (nums in cardNums) { //console.log(cardNums[nums][0]); if (cardNums[nums][0] === 3) { invalidCompanies.push('Amex'); } else if (cardNums[nums][0] === 4) { invalidCompanies.push('Visa'); } else if (cardNums[nums][0] === 5) { invalidCompanies.push('Mastercard'); } else if (cardNums[nums][0] === 6) { invalidCompanies.push('Discover'); } } let unique = (array) => { return [...new Set(array)]; } console.log(unique(invalidCompanies)) //console.log(invalidCompanies); } idInvalidCardCompanies(batch);

Here guys my solution!!
Please give me feedbacks
Thanks a lot

Hello everyone!
Here is the link to my solution. Any comment will be appreciated.

Credit Card Checker

// All valid credit card numbers
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];
const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9];
const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6];
const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5];
const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6];

// All invalid credit card numbers
const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5];
const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3];
const invalid3 = [3, 7, 5, 7, 9, 6, 0, 8, 4, 4, 5, 9, 9, 1, 4];
const invalid4 = [6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5];
const invalid5 = [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4];

// Can be either valid or invalid
const mystery1 = [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4];
const mystery2 = [5, 4, 6, 6, 1, 0, 0, 8, 6, 1, 6, 2, 0, 2, 3, 9];
const mystery3 = [6, 0, 1, 1, 3, 7, 7, 0, 2, 0, 9, 6, 2, 6, 5, 6, 2, 0, 3];
const mystery4 = [4, 9, 2, 9, 8, 7, 7, 1, 6, 9, 2, 1, 7, 0, 9, 3];
const mystery5 = [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3];

const test1 = [4, 7, 1, 6, 4, 3, 7, 8, 4, 7, 6, 6, 0, 3, 8, 9];
const test2 = [4, 5, 5, 6, 7, 7, 6, 5, 4, 5, 9, 7, 0, 5, 7, 1];
const test3 = [5, 3, 8, 7, 9, 9, 3, 6, 7, 8, 7, 0, 9, 4, 7, 6];
const test4 = [3, 7, 6, 9, 7, 2, 6, 3, 4, 2, 6, 2, 4, 5, 1];
const test5 = [6, 0, 1, 1, 0, 6, 7, 3, 3, 1, 3, 0, 0, 3, 8, 1, 7, 9, 5];

// An array of all the arrays above
const batch2 = [test1, test2, test3, test4, test5];

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

// Add your functions below:

function validateCred(arr) {
  let sum = 0;
  let digit = 0;
  let c = 0;
  for (let i = arr.length - 1; i >= 0; i--) {
    c++;
    if (c % 2 == 0 && i != arr.length - 1) {
      digit = arr[i] * 2;
      if (digit > 9) {
        digit -= 9;
      }

      sum += digit;
    } else {
      sum += arr[i];
    }
  }

  if (sum % 10 == 0) {
    return true;
  } else {
    return false;
  }
}

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

function idInvalidCardCompanies(arr) {
  let com = [];
  for (let i = 0; i < arr.length; i++) {
    if (arr[i][0] == 3 && !com.includes("Amex")) {
      com.push("Amex");
    } else if (arr[i][0] == 4 && !com.includes("Visa")) {
      com.push("Visa");
    } else if (arr[i][0] == 5 && !com.includes("Mastercard")) {
      com.push("Mastercard");
    } else if (arr[i][0] == 6 && !com.includes("Discover")) {
      com.push("Discover");
    } else {
      com.push("Company not found");
    }
  }
  return com;
}

const invalid = findInvalidCards(batch);

console.log(idInvalidCardCompanies(invalid));


const testInvalid = findInvalidCards(batch2);
console.log(idInvalidCardCompanies(testInvalid));

Many many hours (over 12 :sweat_smile:) later and here it is. Any feed back appreciated.
Project was frustrating, but worth it.

// All valid credit card numbers const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]; const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9]; const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6]; const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5]; const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6]; // All invalid credit card numbers const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5]; const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3]; const invalid3 = [3, 7, 5, 7, 9, 6, 0, 8, 4, 4, 5, 9, 9, 1, 4]; const invalid4 = [6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5]; const invalid5 = [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4]; // Can be either valid or invalid const mystery1 = [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4]; const mystery2 = [5, 4, 6, 6, 1, 0, 0, 8, 6, 1, 6, 2, 0, 2, 3, 9]; const mystery3 = [6, 0, 1, 1, 3, 7, 7, 0, 2, 0, 9, 6, 2, 6, 5, 6, 2, 0, 3]; const mystery4 = [4, 9, 2, 9, 8, 7, 7, 1, 6, 9, 2, 1, 7, 0, 9, 3]; const mystery5 = [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3]; // 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: function validateCred (array) { let evensDoubled = []; // 0,2,4...indexes let evensDoubledLessNine = [] // let oddTotals = [] // 1,3,5...indexes let oddsSum let total = 0 for ( let i= array.length -2; i >=0; i--) { evensDoubled.push(array[i] * 2); } //return evensDoubled; let j = 0 while (j < evensDoubled.length) { if (evensDoubled[j] < 9 ) { evensDoubledLessNine.push(evensDoubled[j]); } else if (evensDoubled[j] > 9) { evensDoubledLessNine.push(evensDoubled[j] - 9) } j++; } //return evensDoubledLessNine for (i=1; i<array.length ; i+=2) { oddTotals.push(array[i] * 1) } //return oddTotals; let sum2 = evensDoubledLessNine.reduce((accumulator, currentValue) => accumulator + currentValue, 0); //console.log(sum2) let sum3 = oddTotals.reduce((accumulator, currentValue) => accumulator + currentValue, 0); //console.log(sum3) total = sum2+sum3; //return total if (total % 10 === 0) { return true } else { return false } } //console.log(validateCred(invalid3)) function findInvalidCards (nestedArray) { let invalidCards = [] for (i=0; i < nestedArray.length; i++) { if (validateCred(nestedArray[i]) === false) { invalidCards.push(nestedArray[i]) } } return invalidCards } function idInvalidCompanies (nestedArray) { let badCC = []; for ( let i=0; i < nestedArray.length ; i++) switch(nestedArray[i][0]) { case 3: badCC.push(`Amex (American Express) ${nestedArray[i]}`) break; case 4: badCC.push(`Visa ${nestedArray[i]}`) break; case 5: badCC.push(`Mastecard ${nestedArray[i]}`) break; case 6: badCC.push(`Discover ${nestedArray[i]}`) break; case 3: badCC.push(`Amex (American Express) ${nestedArray[i]}`) break; default: badCC.push(`Company not Found`) } return badCC } console.log(idInvalidCompanies(batch)) // GOOD TRY But messed up. Reversed too early and kept the same format. The reversed changes how Luhn algo works // let twoMultiply = [] // let sumlessIndex0 = 0 // function reverseArray (array) { // let rArray = [] // rArray = array.reverse() // return rArray // }; // function twoTimesArray (array) { // for ( i = 1 ; i < array.length; i+=2) { // twoMultiply.push(array[i] * 2) // }return twoMultiply // }; // function lessThanNine(array) { // let copy = [] // for (i=0; i<array.length;i++) { // if (array[i] > 9 ) { // copy.push(array[i] - 9) // } // } return copy // } // function sumCheck (arr1, arr2, arr3) { // let arr1SumOdds = 0 // let arr2TimesTwo = 0 // let arr3LessNine = 0 // for (i=0; i<arr1.length; i+=2) { // arr1SumOdds = arr1SumOdds + arr1[i] // } console.log(arr1SumOdds) // for (i=0; i<arr2.length; i++) { // if (arr2[i] < 9) // arr2TimesTwo = arr2TimesTwo + arr2[i] // } console.log(arr2TimesTwo) // for (i=0; i<arr3.length; i++) { // arr3LessNine = arr3LessNine + arr3[i] // } console.log(arr3LessNine) // return sumlessIndex0 = arr1SumOdds+arr2TimesTwo+ arr3LessNine // } // function validateCred (array) { // let sumIncludesIndexLast = 0 // sumIncludesIndexLast = sumlessIndex0 + array[array.length - 1]; // if (sumIncludesIndexLast % 10 === 0) { // return `valid` // } else { // return `invalid` // } // } // console.log(reverseArray(valid1)) // console.log(twoTimesArray(valid1)) // console.log(lessThanNine(twoMultiply)) // console.log(sumCheck(reverseArray(valid1))) // // ,twoTimesArray(reverseArray),lessThanNine(twoMultiply))) // console.log(validateCred(valid1)) // // console.log(reverseArray(mystery5)[0]) // // function twoTimesArray (array) { // // const copy = []; // // array.forEach(function(arrayItem) { // // copy.push(arrayItem * 2) // // }); return copy // // } // //function lessThanNine (array) { // // array.map (num => { // // //.map doesnt work here as it preserve the lenght of the array. The conditions be return a different size array // // if (num > 9) { // // num - 9 // // } // // }) // // } // // function lessThanNine(array) { // // for (let i = 0; i < array.length; i++) { // // if (array[i] > 9) { // // array[i] -= 9; // Subtracting 9 from elements greater than 9 // // } // // } // // return array;

Here is my solution, please let me know any thoughts to improve. Thanks!

This is my solution, it might be a little bit ugly but it works and I am proud of it :slight_smile:

My solution. I made my own isUnique function to determine if the company was already there. Realize now I could have just used .includes.
main.js

Hello everybody,

Here is my solution : CreditCardChecker

It’s my first attempt and I think it can be improved a lot.
Any comment for improvement is appreciated :slight_smile:

I was really not feeling like iterating backwards to do the initial step of Luhn’s algorithm so I cheated and used array.reverse(). :innocent: At the end I didn’t even remember switch statements existed so I created a function that iterates through an the array with duplicates and pushes only one of the instances to a new array. https://github.com/phoebewoofter/creditCardCheckerChallenger/blob/main/main.js

I started off my validateCred() with declaring a var equal to the modulo of the array length and a single .reduce() on the array. Since the length of the array would have the same modulo as the indexes that would be doubled I didn’t need to iterate backwards. However the .reduce() contained an {if, if else, else} statement that I found hard to read so I scrapped it and used:

[…arr].reverse().map().map().reduce() % === 10

This is a lot easier to read and understand and it ended up being more consice than the single .reduce(if, if else, else)

const batch = [ [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8], // valid1 [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9], // valid2 [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6], // valid3 [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5], // valid4 [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6], // valid5 [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5], // invalid1 [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3], // invalid2 [3, 7, 5, 7, 9, 6, 0, 8, 4, 4, 5, 9, 9, 1, 4], // invalid3 [6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5], // invalid4 [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4], // invalid5 [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4], // mystery1 [5, 4, 6, 6, 1, 0, 0, 8, 6, 1, 6, 2, 0, 2, 3, 9], // mystery2 [6, 0, 1, 1, 3, 7, 7, 0, 2, 0, 9, 6, 2, 6, 5, 6, 2, 0, 3], // mystery3 [4, 9, 2, 9, 8, 7, 7, 1, 6, 9, 2, 1, 7, 0, 9, 3], // mystery4 [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3], // mystery5 ]; const validateCred = (arr) => { return ( //[...arr] is used to create a copy instead of arr to avoid mutating the array when reversing [...arr] .reverse() //map new arr doubling odd indexes on reversed array .map((num, i) => (i % 2 === 1 ? num * 2 : num)) //map new arr subtracting 9 if value over 9 .map((num) => (num > 9 ? num - 9 : num)) //reduce by sum and return sum mod 10 t or f .reduce((acc, curr) => acc + curr, 0) % 10 === 0 ); }; const findInvalidCards = (parentArr) => { // keep the children if validateCred() returns false return parentArr.filter((childArr) => !validateCred(childArr)); }; const idInvalidCardCompanies = (parentArr) => { return ( parentArr //map new arr replacing card numbers with their company name based on the 0 index number .map((childArr) => { switch (childArr[0]) { case 3: return "Amex (American Express)"; break; case 4: return "Visa"; break; case 5: return "Mastercard"; case 6: return "Discover"; default: return "Company not found"; } }) //filter and keep only distinct values .filter((value, i, array) => { return array.indexOf(value) === i; }) ); }; const invalidCards = findInvalidCards(batch); const invalidCardCompanies = idInvalidCardCompanies(invalidCards); console.log( `***INVALID CARD NUMBERS*** \n${invalidCards .map((child) => child.join("")) .sort() .join("\n")}` ); console.log(`\n***OFFENDERS***\n${invalidCardCompanies.join("\n")}`);

Okay, so I wanted to do the last challenge of converting an invalid credit card to a valid credit card number. It’s finally working, but initially it wasn’t. The only thing I changed was the order of my code. Instead of putting my invalidToValid function at the bottom, after screening for company names, I put it directly after my Luhn algorithm function. Why did putting it at the end return unexpected results? Can anyone help me understand this? Oh, and my invalidToValid function changes the check digit by either subtracting the remainder from the og check digit or adding (10 - remainder) to the check digit.

// All valid credit card numbers const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]; const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9]; const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6]; const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5]; const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6]; const valid6 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 4]; // All invalid credit card numbers const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5]; const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3]; const invalid3 = [3, 7, 5, 7, 9, 6, 0, 8, 4, 4, 5, 9, 9, 1, 4]; const invalid4 = [6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5]; const invalid5 = [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4]; // Can be either valid or invalid const mystery1 = [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4]; const mystery2 = [5, 4, 6, 6, 1, 0, 0, 8, 6, 1, 6, 2, 0, 2, 3, 9]; const mystery3 = [6, 0, 1, 1, 3, 7, 7, 0, 2, 0, 9, 6, 2, 6, 5, 6, 2, 0, 3]; const mystery4 = [4, 9, 2, 9, 8, 7, 7, 1, 6, 9, 2, 1, 7, 0, 9, 3]; const mystery5 = [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3]; // 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: // Function checks via Luhn algorithm if credit cards numbers are valid. function validateCred(array) { // Begins by reversing the array so we can more easily iterate through the array (don't have to iterate backwards) while still using Luhn algorithm (i.e., starting from the farthest digit to the right, AKA the check digit, iterate to the left) When we reverse that, we begin with the first indexed number. If we do this, we can also set if...else so that even numbers are left as is and the odd numbers will execute in the iterator after next. let reverseArray = array.reverse(); // As you iterate to the right (since we've reversed), every other digit is doubled (the check digit is not doubled). If the number is greater than 9 after doubling, subtract 9 from its value. let newArray = []; for (let i = 1; i < reverseArray.length; i += 2) { if (reverseArray[i] * 2 < 9) { newArray.push(reverseArray[i] * 2); } else if (reverseArray[i] * 2 >= 9) { newArray.push((reverseArray[i] * 2) - 9); } } // Now add the leftover numbers from the reversed array to the new array. for (let i = 0; i < reverseArray.length; i += 2) { newArray.push(reverseArray[i]); } // Sum up all the digits in the credit card number. let sum = newArray.reduce((accumulator, currentValue) => { return accumulator + currentValue; }); // If the sum modulo 10 is 0 (if the sum divided by 10 has a remainder of 0) then the number is valid, otherwise, it’s invalid. if (sum % 10 === 0) { return true; } else { return false; } } function findRemainder(array) { // Reverse the array const reverseArray = array.slice().reverse(); // Initialize a new array to store modified values const newArray = []; // Double every other digit and handle cases where the result is greater than 9 for (let i = 1; i < reverseArray.length; i += 2) { if (reverseArray[i] * 2 < 9) { newArray.push(reverseArray[i] * 2); } else { newArray.push((reverseArray[i] * 2) - 9); } } // Add the remaining digits from the reversed array for (let i = 0; i < reverseArray.length; i += 2) { newArray.push(reverseArray[i]); } // Calculate the sum of the new array const totalSum = newArray.reduce((accumulator, currentValue) => accumulator + currentValue, 0); // Calculate the remainder const remainder = totalSum % 10; return remainder; } console.log(findRemainder(invalid5)); function invalidToValid(array, remainder) { if (array[array.length - 1] >= remainder) { array[array.length - 1] = array[array.length - 1] - remainder; } else { array[array.length - 1] = array[array.length - 1] + (10 - remainder); } return array; } const valid7 = invalidToValid(invalid5, 1); console.log(validateCred(valid7)); // Keep track of all invalid credit card numbers. function findInvalidCards(nestedArray) { let findTheFoes = nestedArray.filter(array => validateCred(array) === false); return findTheFoes; } // Array of all invalid credit card numbers. let allInvalidCards = findInvalidCards(batch); // Find companies that have mailed out cards with invalid numbers. let idInvalidCardCompanies = nestedArray => { let companyList = []; for (let i = 0; i < nestedArray.length; i++) { if (nestedArray[i][0] === 3) { companyList.push('Amex (American Express)'); } else if (nestedArray[i][0] === 4) { companyList.push('Visa'); } else if (nestedArray[i][0] === 5) { companyList.push('Mastercard'); } else if (nestedArray[i][0] === 6) { companyList.push('Discover'); } else { companyList.push('Company not found'); } } return companyList; } // Assign compaies to an array. let allCompanies = idInvalidCardCompanies(allInvalidCards); // Ensure no duplicates of company names appear by pushing the company names to the new array if they're not already included. So, if Visa's first instane is logged, the second will not. function reduceCompanyList(array) { let reducedCompanyList = []; array.forEach(company => { if (!reducedCompanyList.includes(company)) { reducedCompanyList.push(company); } }); return reducedCompanyList; } console.log(reduceCompanyList(allCompanies));

I know there are better and more efficient ways of writing the invalidToValid function (i.e., only having one parameter and calling the findRemainder function within the invalidToValid function). But I tried so many different things before moving the functions toward the top, I now have one of my worse versions of my code and I am thiiiiis close to rage quitting.

Here’s my solution:

Not sure if I shared this correctly but here’s my solution:

niclog/CreditCardChecker.js

Hi, I’m sending a link to my solution of the project:

I’ll appreciate your feedback.
Best regards
Pawel

Hello everyone!

I had so much fun coding this project, but it was quite challenging for me. I am always amazed by the simplicity of the solutions provided by Codecademy.

Here is the link to my project Gist: Luhn Algorithm, Credit Card Checker · GitHub

here is my solution (Codecademy export · GitHub)

This repository contains JavaScript functions for validating credit card numbers using the Luhn algorithm, identifying invalid card issuers.

Key Features

  • Luhn algorithm implementation: Accurate validation of credit card numbers.
  • Invalid card identification: Detects and isolates invalid card numbers from a dataset.
  • Issuer identification: Determines the potential issuer of invalid cards based on the first digit.

Usage

  • validateCred(cardNumber) : Validates a single credit card number using the Luhn algorithm.
  • findInvalidCards(nestedArray) : Identifies invalid credit card numbers from a nested array.
  • idInvalidCardCompanies(invalidCards) : Determines the potential issuers of invalid cards.
  • convertInvalidToValid(invalidNumber) : Attempts to correct invalid credit card numbers (basic implementation).