-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckSameCase.js
More file actions
64 lines (56 loc) · 1.29 KB
/
Copy pathCheckSameCase.js
File metadata and controls
64 lines (56 loc) · 1.29 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
/**
* Description:
*
* Write a function that will check if two given characters are the same case.
*
* If either of the characters is not a letter, return -1
* If both characters are the same case, return 1
* If both characters are letters, but not the same case, return 0
*
* Examples
* 'a' and 'g' returns 1
* 'A' and 'C' returns 1
* 'b' and 'G' returns 0
* 'B' and 'g' returns 0
* '0' and '?' returns -1
*
*
*
*
* @param {*} a
* @param {*} b
* @returns
*/
function sameCase(a, b) {
let result = -1;
function isLetter(character) {
return /^[a-zA-Z]$/.test(character);
}
if (isLetter(a) && isLetter(b)) {
/^[a-z]{2}$|^[A-Z]{2}$/.test(a + b) ? (result = 1) : (result = 0);
}
return result;
}
// first solution
/*
function sameCase(a, b) {
const ascii_a = a.charCodeAt(0);
const ascii_b = b.charCodeAt(0);
let result = -1;
if (ascii_a >= 65 && ascii_a <= 90 && ascii_b >= 65 && ascii_b <= 90) {
// beide Uppercase
result = 1;
}
if (ascii_a >= 97 && ascii_a <= 122 && ascii_b >= 97 && ascii_b <= 122) {
// beide lowercase
result = 1;
}
if (ascii_a >= 65 && ascii_a <= 90 && ascii_b >= 97 && ascii_b <= 122) {
result = 0;
}
if (ascii_a >= 97 && ascii_a <= 122 && ascii_b >= 65 && ascii_b <= 90) {
result = 0;
}
return result;
}
*/