Skip to content

Instantly share code, notes, and snippets.

@brookr
Created March 8, 2012 18:40
Show Gist options
  • Select an option

  • Save brookr/2002589 to your computer and use it in GitHub Desktop.

Select an option

Save brookr/2002589 to your computer and use it in GitHub Desktop.
JS Master Class assignment #1
var Card = {
isValid: function(strum) {
var sum = 0, mul = 1, length = strum.length, digit, tproduct
forEach(c in strum.slice(0,17)) {
digit = CC.substring(length-i-1,length-i);
tproduct = parseInt(digit ,10)*mul;
sum += (tproduct >= 10 ? (tproduct % 10) + 1 : tproduct)
mul += (mul == 1 ? 1 : -1)
}
return !(sum % 10)
}
}
Card.isValid("5111111111111111")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment