Friday, 15 March 2013

Implementing Luhn algorithm in JavaScript -



Implementing Luhn algorithm in JavaScript -

i'm trying port luhm algorithm implementation have that's in c# javascript. got ported on , thought working, can't legitimate cards validate. amex validates fine, 2 visas reject so. here's code:

luhn = function (number) { var _deltas = [0, 1, 2, 3, 4, -4, -3, -2, -1, 0], _checksum = 0, _digits = [], i, j; while (number != 0) { _digits.push(parseint((number % 10), 10)); number = parseint((number / 10), 10); } (i = (_digits.length - 1), j = _digits.length; > -1; i--) { _digit = _digits[i]; _checksum += _digit; _checksum += ((((i - j) % 2) === 0) ? _deltas[_digit] : 0); } homecoming ((_checksum % 10) === 0); };

can point me in right direction on what's wrong? thought worked fine in c# version, i'm having doubts... in advance!

javascript luhn

No comments:

Post a Comment