-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
134 lines (113 loc) · 3.62 KB
/
Copy pathscript.js
File metadata and controls
134 lines (113 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function submit() {
const MINIMO = 3;
let nome = document.getElementById("nome").value.toUpperCase();
let cognome = document.getElementById("cognome").value.toUpperCase();
let data = document.getElementById("data").value.toUpperCase();
let sesso = document.getElementsByName("sesso");
let luogo = document.getElementById("luogo").value.toUpperCase();
let codiceFiscale = document.getElementById("cf");
function minore(stringaCons, stringaVoc) {
let j = 0;
for(let i = stringaCons.length - 1; i <= MINIMO - 1; i++) {
stringaCons[i] += stringaVoc[j];
j++;
}
return stringaCons;
}
/*function vocali(stringa, stringaVoc) {
for(let i = 0; i < stringa.length; i++) {
if(stringa[i] == "A" || stringa[i] == "E" || stringa[i] == "I" || stringa[i] == "O" || stringa[i] == "U") {
stringaVoc += stringa[i];
stringa = stringa.slice(0, i) + stringa.slice(i + 1);
}
}
}*/
function sommaCheckDigit(start, obj) {
let sum = 0;
for(let i = start; i <= cf.length - 1; i += 2) {
for(let key in obj) {
if(cf[i] == key) {
sum += obj[key];
}
}
}
return sum;
}
//cognome
function surname() {
let cognomeVoc = "";
let cognomeCons = "";
// vocali(cognome, cognomeVoc);
for(let i = 0; i < cognome.length; i++) {
if(cognome[i] == "A" || cognome[i] == "E" || cognome[i] == "I" || cognome[i] == "O" || cognome[i] == "U")
cognomeVoc += cognome[i];
else
cognomeCons += cognome[i];
}
if(cognomeCons.length >= MINIMO)
return cognomeCons.slice(0, MINIMO)
else
return minore(cognomeCons, cognomeVoc)
// return cognome.length >= MINIMO ? cognome.slice(0, MINIMO - 1) : minore(cognome, cognomeVoc);
}
//nome
function name() {
let nomeVoc = "";
let nomeCons = "";
// vocali(nome, nomeVoc);
for(let i = 0; i < nome.length; i++) {
if(nome[i] == "A" || nome[i] == "E" || nome[i] == "I" || nome[i] == "O" || nome[i] == "U")
nomeVoc += nome[i];
else
nomeCons += nome[i];
}
if(nomeCons.length > MINIMO)
return nomeCons[0] + nomeCons.slice(2, 4);
else if(nomeCons.length == MINIMO)
return nomeCons;
else
return minore(nomeCons, nomeVoc);
}
//anno
function year() {
let anno = data.slice(2, 4);
return anno;
}
//mese
function month() {
let mesi = ["A", "B", "C", "D", "E", "H", "L", "M", "P", "R", "S", "T"];
let mese = data.slice(-5, -3);
if(mese < 10)
return mesi[mese[1] - 1];
else
return mesi[mese - 1];
}
// sesso
function sex() {
if(sesso[0].checked)
return 0;
else
return 1;
}
//data
function day() {
let giorno = data.slice(-2);
if(sex())
giorno = parseInt(giorno) + 40;
return giorno;
}
//place
function place() {
return comuni[luogo];
}
//check digit
function checkDigit() {
let cdSum = sommaCheckDigit(0, convDispari)+ sommaCheckDigit(1, convPari);
for(let key in finConv)
if(cdSum % 26 == key)
return finConv[key];
}
cf = surname() + name() + year() + month() + day() + place();
cf += checkDigit();
codiceFiscale.innerText = cf;
}