MCPcopy Index your code
hub / github.com/RandomAPI/Randomuser.me-Node / calculateCheckDigits

Function calculateCheckDigits

api/1.4/data/NO/inject.js:14–31  ·  view source on GitHub ↗
(tenDigits)

Source from the content-addressed store, hash-verified

12 birthDate = dobISO.substr(8, 2) + dobISO.substr(5, 2) + dobISO.substr(2, 2);
13
14 const calculateCheckDigits = (tenDigits) => {
15 const checkDigit = (staticSequence, input) => {
16 input = input.split('').map(Number);
17 let productSum = staticSequence.reduce((acc, value, index) => {
18 return acc + value * input[index];
19 }, 0);
20
21 const sumMod11 = productSum % 11;
22 return (sumMod11 === 0 ? '0' : (11 - sumMod11));
23 };
24 const staticSequenceFirstCheckDigit = [3, 7, 6, 1, 8, 9, 4, 5, 2];
25 const staticSequenceSecondCheckDigit = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
26
27 const k1 = checkDigit(staticSequenceFirstCheckDigit, tenDigits);
28 const k2 = checkDigit(staticSequenceSecondCheckDigit, tenDigits + k1);
29
30 return k1 + '' + k2;
31 };
32
33 const getPersonId = (birthDate, year, gender) => {
34 let no;

Callers 1

getPersonIdFunction · 0.70

Calls 1

checkDigitFunction · 0.70

Tested by

no test coverage detected