const LuhnAlgorithm = num=> {
const inputNum = num.toString();
let sum = 0;
let doubleUp = false;
/* from the right to left, double every other digit starting with the second to last digit.*/
for (let i = inputNum.length - 1; i >= 0; i--) {
let curDigit = parseInt(inputNum.charAt(i));
/* double every other digit starting with the second to last digit */
if (doubleUp) {
/* doubled number is greater than 9 than subtracted 9 */
if (curDigit * 2 > 9) {
sum += curDigit * 2 - 9;
} else {
sum += curDigit * 2;
}
} else {
sum += curDigit;
}
doubleUp = !doubleUp;
}
return sum % 10 == 0 ? true : false;
}