Created
March 8, 2012 18:40
-
-
Save brookr/2002589 to your computer and use it in GitHub Desktop.
JS Master Class assignment #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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