--- al01/12.js
+++ al01/12.js
... | ... | @@ -1,24 +1,14 @@ |
1 | 1 |
//문자열을 입력받아 모두 대문자로 변환 후 출력 |
2 |
+function upper(str){ |
|
2 | 3 |
|
3 |
-let munja = "ItisTimeToStudy"; |
|
4 |
+ let answer = ""; |
|
5 |
+ for(let s of str){ |
|
6 |
+ let asciiNum = s.charCodeAt(); |
|
4 | 7 |
|
5 |
-function upper(munja){ |
|
6 |
- |
|
7 |
- let munjaAscii = []; |
|
8 |
- let munjaString = []; |
|
9 |
- for(let i = 0; i < munja.length; i++){ |
|
10 |
- munjaAscii.push(munja.charCodeAt(i)); |
|
8 |
+ if(asciiNum >= 97 && asciiNum <= 122) answer += String.fromCharCode(asciiNum - 32); |
|
9 |
+ else answer += s; |
|
11 | 10 |
} |
12 |
- for(let i = 0; i < munjaAscii.length; i++){ |
|
13 |
- if(munjaAscii[i] >= 97 && munjaAscii[i] <= 122){ |
|
14 |
- munjaAscii[i] = munjaAscii[i] - 32; |
|
15 |
- } |
|
16 |
- } |
|
17 |
- for(let i = 0; i < munjaAscii.length; i++){ |
|
18 |
- munjaString.push(String.fromCharCode(munjaAscii[i])); //아스키코드->문자 |
|
19 |
- } |
|
20 |
- return munjaString.join(''); |
|
21 |
- |
|
11 |
+ return answer; |
|
22 | 12 |
} |
23 | 13 |
|
24 |
-console.log(upper(munja));(No newline at end of file) |
|
14 |
+console.log(upper("ItisTimeToStudy"));(No newline at end of file) |
--- al01/13.js
+++ al01/13.js
... | ... | @@ -1,19 +1,16 @@ |
1 | 1 |
//문자열을 입력받아 upper->lower, lower->upper |
2 | 2 |
function solution(str){ |
3 | 3 |
|
4 |
- strAscii = []; |
|
5 |
- answer = []; |
|
4 |
+ answer = ""; |
|
6 | 5 |
|
7 |
- for(let i = 0; i < str.length; i++){ |
|
8 |
- strAscii.push(str.charCodeAt(i)); //Character -> ASCII |
|
9 |
- |
|
10 |
- if(strAscii[i] >= 65 && strAscii[i] <= 90) strAscii[i] += 32; //upper->lower |
|
11 |
- else strAscii[i] -= 32; //lower->upper |
|
6 |
+ for(let s of str){ |
|
7 |
+ let asciiNum = s.charCodeAt(); //char->ASCII |
|
12 | 8 |
|
13 |
- answer.push(String.fromCharCode(strAscii[i])); //ASCII -> Character |
|
9 |
+ if(asciiNum >= 65 && asciiNum <= 90) answer += String.fromCharCode(asciiNum + 32); //upper->lower |
|
10 |
+ else /*****************************/ answer += String.fromCharCode(asciiNum - 32); //lower->upper |
|
14 | 11 |
} |
15 | 12 |
|
16 |
- return answer.join(''); |
|
13 |
+ return answer; |
|
17 | 14 |
|
18 | 15 |
} |
19 | 16 |
|
--- al01/14.js
+++ al01/14.js
... | ... | @@ -3,10 +3,7 @@ |
3 | 3 |
let max = arr[0]; |
4 | 4 |
|
5 | 5 |
for(let i = 0; i < arr.length; i++){ |
6 |
- |
|
7 |
- if(max.length < arr[i].length){ |
|
8 |
- max = arr[i]; |
|
9 |
- } |
|
6 |
+ if(max.length < arr[i].length) max = arr[i]; |
|
10 | 7 |
} |
11 | 8 |
return max; |
12 | 9 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?