-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-same-case.js
More file actions
50 lines (35 loc) · 1.63 KB
/
check-same-case.js
File metadata and controls
50 lines (35 loc) · 1.63 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
//8 Kyu
//Check and Same Case
//Fundamentals
// 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
//Solution
function sameCase(a, b){
//set up a str with alphabet both in caps and not
let alphabet = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'
//check if the characters are both letters if not return -1
if(alphabet.indexOf(a) === -1 || alphabet.indexOf(b) === -1) return -1
//then check if the characters are both same case if so return 1
if((a === a.toLowerCase() && b === b.toLowerCase()) || (a === a.toUpperCase() && b === b.toUpperCase())){
return 1
//else if the characters are letters but not the same case return 0
}else{
return 0
}
}
//str1 -> str character that can be lower case, uppecase or a symbol. Wont be empty, wont be null or undefined, always will be a single str character
//str2 -> str character that can be lower case, uppecase or a symbol. Wont be empty, wont be null or undefined, always will be a single str character
//num -> depending on a few conditionals return the following: if either character is not a letter return -1
//if both characters are the same case return 1
//if both characters are letter but not the same case return 0
console.log(sameCase('e', '%'), -1)
console.log(sameCase('e', 'f'), 1)
console.log(sameCase('e', 'G'), 0)