-
Notifications
You must be signed in to change notification settings - Fork 1
/
Check some case.js
33 lines (26 loc) · 985 Bytes
/
Check some case.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
/*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*/
function sameCase(a, b) {
let small = 'abcdefghijklmnopqrstuvwxyz'
let caps = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
return !small.includes(a) && !caps.includes(a) || !small.includes(b) && !caps.includes(b) ? -1:
small.includes(a) && small.includes(b) ? 1:
caps.includes(a) && caps.includes(b) ? 1: 0
}
function sameCase(a, b) {
if (a.toUpperCase() === a.toLowerCase() || b.toLowerCase() === b.toUpperCase()) {
return -1
} else if (a === a.toLowerCase() && b === b.toLowerCase() || a === a.toUpperCase() && b === b.toUpperCase()) {
return 1
} else {
return 0
}
}