Skip to content

Commit a2b4e1e

Browse files
committed
Refactor code to make TypeScript happy
1 parent e1ead8a commit a2b4e1e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ export default function isValidNIP(rawNip: string | number): boolean {
1515

1616
// calculate checksum
1717
let sum = 0;
18-
for (let position = 0; position < weights.length; position += 1) {
19-
const weight = weights[position];
20-
const digit = parseInt(nip[position], 10);
18+
weights.forEach((weight, position) => {
19+
const digit = Number(nip[position]);
2120
sum += weight * digit;
22-
}
21+
});
2322

2423
const checksum = sum % 11;
2524

2625
if (checksum === 10) {
2726
return false;
2827
}
2928

30-
return checksum === parseInt(nip[9], 10);
29+
return checksum === Number(nip[9]);
3130
}

0 commit comments

Comments
 (0)