Skip to content

Instantly share code, notes, and snippets.

@trivektor
Created November 10, 2011 19:37
Show Gist options
  • Select an option

  • Save trivektor/1355915 to your computer and use it in GitHub Desktop.

Select an option

Save trivektor/1355915 to your computer and use it in GitHub Desktop.
Exercise for JS Master Class
function isCreditCard( CC ) {
if (CC.length > 19)
return (false);
var sum = 0, mul = 1, l = CC.length, digit;
for (var i = l; i > 0; i--) {
digit = CC.substring(i-1, i);
tproduct = parseInt(digit)*mul;
sum += tproduct >= 10 ? (tproduct % 10) + 1 : tproduct;
mul = (mul == 1) ? mul + 1 : mul - 1;
}
return (sum % 10) == 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment