forked from Avdhesh-Varshney/WebMasterLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
31 lines (25 loc) · 843 Bytes
/
script.js
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
function areIsomorphic(str1, str2) {
if (str1.length !== str2.length) return false;
let map1 = {}, map2 = {};
for (let i = 0; i < str1.length; i++) {
let char1 = str1[i], char2 = str2[i];
if ((map1[char1] && map1[char1] !== char2) || (map2[char2] && map2[char2] !== char1)) {
return false;
}
map1[char1] = char2;
map2[char2] = char1;
}
return true;
}
function checkIsomorphism() {
const string1 = document.getElementById('string1').value;
const string2 = document.getElementById('string2').value;
const output = document.getElementById('output');
if (areIsomorphic(string1, string2)) {
output.textContent = 'The strings are isomorphic.';
output.style.color = 'darkgreen';
} else {
output.textContent = 'The strings are not isomorphic.';
output.style.color = 'darkred';
}
}