Skip to content

Instantly share code, notes, and snippets.

@kennystone
Created December 12, 2011 18:42
Show Gist options
  • Save kennystone/1468518 to your computer and use it in GitHub Desktop.
Save kennystone/1468518 to your computer and use it in GitHub Desktop.
foldR: function(str, acc, fun) {
var i,
len = str.length,
for(i = 0; i < len; i++) {
acc = fun(acc, str.substring(len-i-1,len-i));
}
}
isCreditCard( CC ) {
if (CC.length > 19)
return (false);
var sum,
mul = 1,
tproduct;
sum = foldR(CC, 0, function(acc, digit) {
tproduct = parseInt(digit,10)*mul;
if (mul == 1)
mul++;
else
mul--;
if (tproduct >= 10)
return(acc + (tproduct % 10) + 1);
else
return(acc + product);
}
if ((sum % 10) == 0)
return (true);
return (false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment