-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day18.js
36 lines (25 loc) · 947 Bytes
/
Day18.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
// Coding Challenge
// 17: Write a function to check if a character is uppercase or lowercase.
// Constraints:
// The input char will be a single character.
// The character can be any printable ASCII character.
// You can assume that the input will always be a string of length 1.
// Notes:
// Ensure that the function correctly identifies uppercase characters based on their ASCII values.
// Optimize the function to handle edge cases efficiently.
// 1st method
const isUpperCase = (char) =>{
if(char.charCodeAt(0) >=65 && char.charCodeAt(0) <=90){
return true;
}
return false;
}
// 2nd method
const isLowerCase = (char) => {
return char === char.toLowerCase();
}
// The ASCII values for uppercase letters range from 65 to 90,
// while the ASCII values for lowercase letters range from 97 to 122.
// Example usage:
console.log(isUpperCase("s")); // Output: false
console.log(isLowerCase("s")); // Output: true