728x90
๐ 12 - ๋์๋ฌธ์ ๋ณํ
๋๋ฌธ์์ผ๋ ์๋ฌธ์๋ก ์๋ฌธ์์ผ๋๋ ๋๋ฌธ์๋ก ๋ณํ์ํค๋๋ฐ ASCII
๋ฐฉ๋ฒ๊ณผ toUpperCase, toLowerCase
๋ฐฉ๋ฒ์ผ๋ก ๋๋์ด ํ์๋ค.
console.log(solution("StuDY"));
function solution(s) {
let ans = "";
for(let x of s){
let num = x.charCodeAt();
if(num>=65 && num<=91) ans+=String.fromCharCode(num+32);
else ans+=String.fromCharCode(num-32);
}
return ans;
}
function solution(s) {
let ans = "";
for(let x of s){
if (x === x.toUpperCase()) ans+=x.toLowerCase();
else ans += x.toUpperCase();
}
return ans;
}
๋ฐ์ํ
'Algorithm > ์ธํ๋ฐ(inflearn)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ ์๋ฐ์คํฌ๋ฆฝํธ(JavaScript) ] 14 - ๊ฐ์ด๋ฐ ๋ฌธ์ ์ถ๋ ฅ (0) | 2021.08.12 |
---|---|
[ ์๋ฐ์คํฌ๋ฆฝํธ(JavaScript) ] 13 - ๊ฐ์ฅ ๊ธด ๋ฌธ์์ด (0) | 2021.08.12 |
[ ์๋ฐ์คํฌ๋ฆฝํธ(JavaScript) ] 11 - ๋๋ฌธ์๋ก ํต์ผ (0) | 2021.08.12 |
[ ์๋ฐ์คํฌ๋ฆฝํธ(JavaScript) ] 10 - ๋ฌธ์ ์ฐพ๊ธฐ (0) | 2021.08.11 |
[ ์๋ฐ์คํฌ๋ฆฝํธ(JavaScript) ] 09 - A๋ฅผ #์ผ๋ก (0) | 2021.08.11 |
๋๊ธ