-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy pathrobinyoon-dev.js
More file actions
52 lines (39 loc) ยท 1.44 KB
/
robinyoon-dev.js
File metadata and controls
52 lines (39 loc) ยท 1.44 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
/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function (s) {
//NOTE: ๋ค์์๋ ํฌ ํฌ์ธํฐ ๋ฐฉ์์ผ๋ก ๋ถ์ด๋ณด๊ฒ ์ต๋๋ค...
//0. ์ฃ์ง์ผ์ด์ค ๋๋น: ๋น์นธ์ธ ๊ฒฝ์ฐ.
if (s.trim() === '') {
return true;
}
//1. s๋ฅผ array๋ก ๋ณํ
const sArray = Array.from(s);
// ์ํ๋ฒณ๋ง ๋จ๊ธฐ๋ ์์
// (Alphanumeric characters include letters and numbers.)
const aAscii = 'a'.charCodeAt(0);
const zAscii = 'z'.charCodeAt(0);
const aUpperAscii = 'A'.charCodeAt(0);
const zUpperAscii = 'Z'.charCodeAt(0);
const zeroAscii = '0'.charCodeAt(0);
const nineAscii = '9'.charCodeAt(0);
const filteredArray = [];
for (let char of sArray) {
let charAscii = char.charCodeAt(0);
let isCharacter = (charAscii >= aAscii && charAscii <= zAscii) || (charAscii >= aUpperAscii && charAscii <= zUpperAscii) || (charAscii >= zeroAscii && charAscii <= nineAscii);
if (isCharacter) {
filteredArray.push(char);
}
}
// ๋๋ฌธ์ -> ์๋ฌธ์๋ก ๋ณ๊ฒฝํ๋ ์์
const lowerArray = [];
for (let char of filteredArray) {
lowerArray.push(char.toLowerCase());
}
// reverse ํด๋ ๋๊ฐ์์ง ํ์ธํ๋ ์์
const reversedArray = [...lowerArray].reverse();
const originalString = lowerArray.join();
const reversedString = reversedArray.join();
return originalString === reversedString;
};