Created
          October 20, 2010 15:48 
        
      - 
      
 - 
        
Save johnfmorton/636673 to your computer and use it in GitHub Desktop.  
    Is it a credit card function for JS class
  
        
  
    
      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
    
  
  
    
  | Number.prototype.isCreditCard = ( | |
| function() { | |
| var testCC = this.toString(); | |
| var sum =0; mul = 1; l = testCC.length; | |
| if (l < 19) { | |
| for (i = 0; i < l; i++) | |
| { | |
| var digit = testCC.substring(l-i-1,l-i); | |
| var tproduct = parseInt(digit ,10)*mul; | |
| if (tproduct >= 10) | |
| sum += (tproduct % 10) + 1; | |
| else | |
| sum += tproduct; | |
| if (mul == 1) | |
| mul++; | |
| else | |
| mul--; | |
| } | |
| if ((sum % 10) == 0) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| ); | |
| (5555555555554444).isCreditCard(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment