안효원 안효원 2022-02-21
num13 modified
@33e7c3c5d7811b108f1eaf34e755cec2296860c3
al01/12.js
--- al01/12.js
+++ al01/12.js
@@ -1,24 +1,14 @@
 //문자열을 입력받아 모두 대문자로 변환 후 출력
+function upper(str){
 
-let munja = "ItisTimeToStudy";
+    let answer = "";
+    for(let s of str){
+        let asciiNum = s.charCodeAt();
 
-function upper(munja){
-
-    let munjaAscii = [];
-    let munjaString = [];
-    for(let i = 0; i < munja.length; i++){
-        munjaAscii.push(munja.charCodeAt(i));
+        if(asciiNum >= 97 && asciiNum <= 122) answer += String.fromCharCode(asciiNum - 32);
+        else answer += s;
     }
-    for(let i = 0; i < munjaAscii.length; i++){
-        if(munjaAscii[i] >= 97 && munjaAscii[i] <= 122){
-            munjaAscii[i] = munjaAscii[i] - 32;
-        }
-    }
-    for(let i = 0; i < munjaAscii.length; i++){
-        munjaString.push(String.fromCharCode(munjaAscii[i])); //아스키코드->문자
-    }
-    return munjaString.join('');
-
+    return answer;
 }
 
-console.log(upper(munja));
(No newline at end of file)
+console.log(upper("ItisTimeToStudy"));
(No newline at end of file)
al01/13.js
--- al01/13.js
+++ al01/13.js
@@ -1,19 +1,16 @@
 //문자열을 입력받아 upper->lower, lower->upper
 function solution(str){
 
-    strAscii = [];
-    answer = [];
+    answer = "";
 
-    for(let i = 0; i < str.length; i++){  
-        strAscii.push(str.charCodeAt(i));                  //Character -> ASCII
-        
-        if(strAscii[i] >= 65 && strAscii[i] <= 90) strAscii[i] += 32; //upper->lower
-        else strAscii[i] -= 32;                                       //lower->upper
+    for(let s of str){  
+        let asciiNum = s.charCodeAt();   //char->ASCII
 
-        answer.push(String.fromCharCode(strAscii[i]));          //ASCII -> Character
+        if(asciiNum >= 65 && asciiNum <= 90) answer += String.fromCharCode(asciiNum + 32);   //upper->lower
+        else /*****************************/ answer += String.fromCharCode(asciiNum - 32);   //lower->upper
     }
 
-    return answer.join('');
+    return answer;
 
 }
 
al01/14.js
--- al01/14.js
+++ al01/14.js
@@ -3,10 +3,7 @@
     let max = arr[0];
 
     for(let i = 0; i < arr.length; i++){
-        
-        if(max.length < arr[i].length){
-            max = arr[i];
-        }
+        if(max.length < arr[i].length) max = arr[i];
     }
     return max;
 
Add a comment
List