-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday47.js
46 lines (31 loc) · 1.01 KB
/
day47.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// js program to perform string comparison
const string1 = 'JavaScript Program';
const string2 = 'javascript program';
// compare both strings
const result = string1.toUpperCase() === string2.toUpperCase();
if(result) {
console.log('The strings are similar.');
} else {
console.log('The strings are not similar.');
}
// program to perform string comparison
const string1 = 'JavaScript Program';
const string2 = 'javascript program';
// create regex
const pattern = new RegExp(string1, "gi");
// compare the stings
const result = pattern.test(string2)
if(result) {
console.log('The strings are similar.');
} else {
console.log('The strings are not similar.');
}
// program to perform case insensitive string comparison
const string1 = 'JavaScript Program';
const string2 = 'javascript program';
const result = string1.localeCompare(string2, undefined, { sensitivity: 'base' });
if(result == 0) {
console.log('The strings are similar.');
} else {
console.log('The strings are not similar.');
}