H Johnson - 2014-02-09 22:08:56
This will do the same thing, just more quickly:
var sumTable = [[0,1,2,3,4,5,6,7,8,9],
[0,2,4,6,8,1,3,5,7,9]];
var sum = 0, flip = 0;
for (var i=cardNo.length-1; i>= 0; i--)
sum += sumTable[flip++ & 0x1][Number(cardNo.charAt(i))];
Have fun with it. I rewrote it in php from what someone else had done in java.