🗃️javascript/코테 프레임 문제

1-12 대문자로 통일[아스키 코드 활용]

하얀성 2023. 9. 21. 08:52

문제는 어렵지 않았다. 아스키 코드 활용은 헷갈렸다.

아스키

대문자 : 65 ~ 90

소문자 : 97~122

function solution(s){
  return [...s].map(x => x.toUpperCase()).join("");
}

let str="ItisTimeToStudy";
console.log(solution(str));

 

<아스키 활용코드>

function solution(s){
  return [...s].map(x => x.charCodeAt() >= 65 && x.charCodeAt() <= 90 ? x : x.toUpperCase() ).join("");
}

let str="ItisTimeToStudy";
console.log(solution(str));