function check(code) { code = code.split(''); var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2], parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2], sum = 0, ai = 0, wi = 0; for (var i = 0; i < 17; i++) { ai = code[i]; wi = factor[i]; sum += ai * wi; } var last = parity[sum % 11]; console.log(last) return (parity[sum % 11] == code[17]); }
标签:parity,code,ai,sum,wi,校验码,var From: https://www.cnblogs.com/hhdom/p/17032199.html