
function solution(str){
let result = 0;
for(let x of str) {
if(x===x.toUpperCase()) result++;
}
return result;
}
let str = 'ComPuterProGramming' ;
console.log(solution(str)); // 4
⇒ toUpperCase() 메서드는 대문자로 바꿔주는 메서드
: charCodeAt() 메서드는 주어진 index에 해당하는 유니코드 값을 리턴
function solution(str){
let result = 0;
for(let x of str) {
let num = x.charCodeAt();
if(num>=65 && num<=90) result++;
}
return result;
}
let str = 'ComPuterProGramming' ;
console.log(solution(str)); // 4
⇒ ASCII Code에서 대문자는 65~90, 소문자는 97~122