Skip to content

Commit

Permalink
Simplify reduce function
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktorwojcik112 committed Oct 2, 2021
1 parent 9206a10 commit ec4801d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ const validators = {
8: 9,
9: 1,
10: 3,
11: 1,
11: 0,
};

if (str != null && str.length === 11 && isInt(str, { allow_leading_zeroes: true })) {
const digits = str.split('').slice(0, -1);
const sum = digits.reduce((acc, digit, index) => {
if (index !== 10) {
acc += (Number(digit) * weightOfDigits[index + 1]);
}

return acc;
}, 0);
const sum = digits.reduce((acc, digit, index) =>
acc + (Number(digit) * weightOfDigits[index + 1]), 0);

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

0 comments on commit ec4801d

Please sign in to comment.