-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresearchString.js
More file actions
91 lines (63 loc) · 2.1 KB
/
researchString.js
File metadata and controls
91 lines (63 loc) · 2.1 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
// there is other js in 'webSites/index.html'
//this is the map where the program put the char as key and the number of char in the string is the value
let hashStringa = new Map();
let hashArray = new Map();
//es: jack --> [[j,1],[a,1],[c,1],[k,1]]
//this is the function you must copy for searc a string
function search() {
hashStringa.clear();
hashArray.clear()
document.getElementById("similar").innerHTML = '';
let stringa = document.getElementById("search").value; //this is the variable to search in the array
console.log(stringa);
mappingString(1, stringa);
for (let i = 0; i < array.length; i++) {
mappingString(0, array[i]);
//punteggio in italian is point
let punteggio = 0;
//dare il punteggio
for (let x = 0; x < hashStringa.size; x++) {
}
hashStringa.forEach((value, key, char) => {
if (hashArray.has(key) == true) {
punteggio++;
if (value == hashArray.get(key)) {
punteggio += 3;
}
}
});
//median of punteggio
punteggio /= hashStringa.size;
if (punteggio >= 3) {
document.getElementById("similar").innerHTML += '<li>' + array[i] + '</li>';
}
console.log(punteggio);
hashArray.clear();
}
}
function mappingString(num, stringa) {
//this is an array for separete the char of the 'stringa'
let arrayChar = [];
let key;
let value = 0;
for (let i = 0; i < stringa.length; i++) {
if (!arrayChar.includes(stringa[i])) {
arrayChar.push(stringa[i]);
key = stringa[i];
console.log(key); // Mostra il nuovo carattere unico
for (x = 0; x < stringa.length; x++) {
if (key === stringa[x]) {
value++;
}
}
console.log(value);
if (num == 1) {
hashStringa.set(key, value);
}
else {
hashArray.set(key, value);
}
value = 0;
}
}
}