Skip to content

Commit ec4801d

Browse files
Simplify reduce function
1 parent 9206a10 commit ec4801d

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/lib/isIdentityCard.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@ const validators = {
1616
8: 9,
1717
9: 1,
1818
10: 3,
19-
11: 1,
19+
11: 0,
2020
};
2121

2222
if (str != null && str.length === 11 && isInt(str, { allow_leading_zeroes: true })) {
2323
const digits = str.split('').slice(0, -1);
24-
const sum = digits.reduce((acc, digit, index) => {
25-
if (index !== 10) {
26-
acc += (Number(digit) * weightOfDigits[index + 1]);
27-
}
28-
29-
return acc;
30-
}, 0);
24+
const sum = digits.reduce((acc, digit, index) =>
25+
acc + (Number(digit) * weightOfDigits[index + 1]), 0);
3126

3227
const modulo = sum % 10;
3328
const lastDigit = Number(str.charAt(str.length - 1));

0 commit comments

Comments
 (0)