728x90
๋ฐ์ํ
๐ ๋ฌธ์
๋๋ฌธ์์ ์๋ฌธ์๊ฐ ๊ฐ์ด ์กด์ฌํ๋ ๋ฌธ์์ด์ ์ ๋ ฅ๋ฐ์ ๋๋ฌธ์๋ก ๋ชจ๋ ํต์ผํ์ฌ ๋ฌธ์์ด์ ์ถ๋ ฅํ๋ ๋ฌธ์ ์ด๋ค.
๋๋ ๋ฌธ์์ด ์ ์ฒด๋ฅผ toUpperCase() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋๋ฌธ์๋ก ํต์ผํด์ฃผ์๋ค.
๋ํ, ๋๋ฌธ์ ์ฐพ๊ธฐ ๋ฌธ์ ์์ ์ฌ์ฉํ๋ charCodeAt() ๋ฉ์๋์, ์์คํค์ฝ๋ ๋ฒํธ๋ฅผ ๋ฐ์ ๋ฌธ์์ด์ ๊ตฌ์ฑํด์ฃผ๋ String.fromCharCode() ๋ฉ์๋๋ฅผ ๊ฐ์ด ์ฌ์ฉํ ๋ฐฉ๋ฒ๋ ์์๋ณด์๋ค.
๐ ํ์ด
// toUpperCase() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ฝ๋
function solution(s) {
let answer = '';
answer = s.toUpperCase();
return answer;
}
let str = 'ItisTimeToStudy';
console.log(solution(str));
// charCodeAt(), String.fromCharCode() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ฝ๋
function solution(s) {
let answer = '';
for (let x of s) {
let num = x.charCodeAt();
if (num >= 97 && num <= 122) answer += String.fromCharCode(num - 32);
else answer += x;
}
return answer;
}
let str = 'ItisTimeToStudy';
console.log(solution(str));
'Algorithm > ์ธํ๋ฐ(inflearn)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JavaScript/section 1] 14 - ๊ฐ์ฅ ๊ธด ๋ฌธ์์ด (0) | 2022.09.04 |
---|---|
[JavaScript/section 1] 13 - ๋์๋ฌธ์ ๋ณํ (0) | 2022.09.03 |
[JavaScript/section 1] 11 - ๋๋ฌธ์ ์ฐพ๊ธฐ (0) | 2022.09.02 |
[JavaScript/section 1] 10 - ๋ฌธ์ ์ฐพ๊ธฐ (0) | 2022.09.02 |
[JavaScript/section 1] 09 - A๋ฅผ #์ผ๋ก (0) | 2022.09.01 |