728x90
๋ฐ์ํ
๐ ๋ฌธ์
ํ ๊ฐ์ ๋ฌธ์์ด์ ์ ๋ ฅ๋ฐ์ ํด๋น ๋ฌธ์์ด์ ์ํ๋ฒณ ๋๋ฌธ์๊ฐ ๋ช ๊ฐ ์๋์ง ์์๋ด๋ ๋ฌธ์ ์ด๋ค.
๋๋ charCodeAt() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋ฒณ ๋๋ฌธ์์ ์์คํค์ฝ๋ ๋ฒํธ๊ฐ 90๊น์ง๋ผ๋ ๊ฒ์ ์ด์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์๋ค.
ํ์ง๋ง ์ด๋ณด๋ค toUpperCase() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด๋ผ๊ณ ํ๋ค.
๐ ํ์ด
// charCodeAt() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ฝ๋
function solution(s) {
let answer = 0;
for (let x of s) {
if (x.charCodeAt() < 91) answer++;
}
return answer;
}
let str = 'KoreaTimeGood';
console.log(solution(str));
// toUpperCase() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ฝ๋
function solution(s) {
let answer = 0;
for (let x of s) {
if (x === x.toUpperCase()) answer++;
}
return answer;
}
let str = 'KoreaTimeGood';
console.log(solution(str));
'Algorithm > ์ธํ๋ฐ(inflearn)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JavaScript/section 1] 13 - ๋์๋ฌธ์ ๋ณํ (0) | 2022.09.03 |
---|---|
[JavaScript/section 1] 12 - ๋๋ฌธ์๋ก ํต์ผ (0) | 2022.09.02 |
[JavaScript/section 1] 10 - ๋ฌธ์ ์ฐพ๊ธฐ (0) | 2022.09.02 |
[JavaScript/section 1] 09 - A๋ฅผ #์ผ๋ก (0) | 2022.09.01 |
[JavaScript/section 1] 08 - ์ผ๊ณฑ ๋์์ด (0) | 2022.09.01 |