Here’s my solution; it may not be elegant, but it works. Feel free to share your thoughts. This challenge was intimidating, at first, but we’ve got this and whatever comes next. Good luck everyone!
const validateCred = arr => {
let oddNums =
let evenNums =
let oddNumSum = 0
let evenNumSum = 0
for (i = arr.length - 2; i >= 0; i -= 2 ) {
oddNums.push((arr[i] * 2))
}
for (k = 0; k < oddNums.length; k++) {
if (oddNums[k] > 9) {
oddNums[k] = oddNums[k] - 9
}
}
for (l = 0; l < oddNums.length; l++) {
oddNumSum += oddNums[l]
}
for (j = arr.length - 1; j >= 0; j -= 2) {
evenNums.push(arr[j])
}
for (m = 0; m < evenNums.length; m++) {
evenNumSum += evenNums[m]
}
if ((evenNumSum + oddNumSum) % 10 === 0) {
return true
} else {
return false
}
}
let invalidList =
const findInvalidCards = nest => {
for (n = 0; n < nest.length; n++) {
if (validateCred(nest[n]) === false) {
invalidList.push(nest[n])
}
}
return invalidList
}
findInvalidCards(batch)
console.log(invalidList)
let invalidListNames =
const idInvalidCardCompanies = invalidArr => {
for (o = 0; o < invalidArr.length; o++) {
if (invalidArr[o][0] === 3) {
invalidListNames.push(‘Amex’)
}
else if (invalidArr[o][0] === 4) {
invalidListNames.push(‘Visa’)
}
else if (invalidArr[o][0] === 5) {
invalidListNames.push(‘Mastercard’)
}
else if (invalidArr[o][0] === 6) {
invalidListNames.push(‘Discover’)
}
else {
invalidListNames.push(Company not found
)
}
}
return console.log(invalidListNames.filter((value, index) => invalidListNames.indexOf(value) === index))
}
idInvalidCardCompanies(invalidList)