2023. 7. 23. 18:00ใStudy_Develop/์๊ณ ๋ฆฌ์ฆ | ์ฝ๋ฉํ ์คํธ
๋ฌธ์
์์ด ์ํ๋ฒณ์ผ๋ก ์ด๋ฃจ์ด์ง ๋ฌธ์์ด str์ด ์ฃผ์ด์ง๋๋ค. ๊ฐ ์ํ๋ฒณ์ ๋๋ฌธ์๋ ์๋ฌธ์๋ก ์๋ฌธ์๋ ๋๋ฌธ์๋ก ๋ณํํด์ ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์.
์ ํ์ฌํญ
1 ≤ str์ ๊ธธ์ด ≤ 20
str์ ์ํ๋ฒณ์ผ๋ก ์ด๋ฃจ์ด์ง ๋ฌธ์์ด์
๋๋ค.
์ ์ถ๋ ฅ ์
์ ๋ ฅ : aBcDeFg
์ถ๋ ฅ : AbCdEfG
ํ์ด
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = [line];
}).on('close',function(){
str = input[0];
const splitedStr = [...str]
const result = splitedStr.map(a => {
const curCodeAt = a.charCodeAt()
if(curCodeAt >= 97) return a.toUpperCase()
return a.toLowerCase()
})
console.log(result.join(""))
});
ํด์ค
- const splitedStr = [...str] : ์คํ๋ ๋ ๊ตฌ๋ฌธ์ str์ ๊ฐ๋ณ ๋ฌธ์๋ฅผ ๋ฐฐ์ด์ ๊ฐ๋ณ ์์๋ก ๋ณต์ฌํ์ฌ ์๋ฐฐ์ด splitedStr์ ๋ง๋๋๋ฐ ์ฌ์ฉ๋๋ค.
- splitSize๋ฐฐ์ด์ ๊ฐ ์์ a์ ๋ํด a.charCodeAt()ํจ์๋ฅผ ์ฌ์ฉํ์ฌ a์ ๋ฌธ์ ์ฝ๋๋ฅผ ์ป๋๋ค.
- curCodeAt๋ณ์์ ๋ฌธ์ ์ฝ๋๋ฅผ ์ ์ฅํ๋ค.
- ์กฐ๊ฑด ๋ฌธ์ ์ฌ์ฉํ์ฌ curCodeAt์ ๊ฐ์ด 97์ด์์ธ ๊ฒฝ์ฐ, return a.toUpperCase();๋ฅผ ์คํํ๋ค.
์ด๋ a๋ฅผ ๋๋ฌธ์๋ก ๋ณํํ์ฌ ๋ฐํํ๋ค.
- curCodeAt์ ๊ฐ์ด 97๋ฏธ๋ง์ธ ๊ฒฝ์ฐ, return a.toLowerCase();๋ฅผ ์คํํ๋ค.
์ด๋ a๋ฅผ ์๋ฌธ์๋ก ๋ณํํ์ฌ ๋ฐํํ๋ค.
toUpperCase
toUpperCase() ๋ฉ์๋๋ ๋ฌธ์์ด์ ๋๋ฌธ์๋ก ๋ณํํด ๋ฐํํ๋ค.
toLowerCase()
toLowerCase()๋ ๋ฌธ์์ด ๋ด์ ๋ชจ๋ ๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ณ๊ฒฝํ๋ค.
join ํจ์๋?
์ ์ฝ๋ result.join("")์ result๋ฐฐ์ด์ ์์๋ฅผ ๋จ์ผ ๋ฌธ์์ด๋ก ๊ฒฐํฉํ๋ ๋ฉ์๋ ํธ์ถ์ด๋ค.
join()๋ฉ์๋๋ ์ง์ ๋ ๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐฐ์ด์ ๋ชจ๋ ์์๋ฅผ ๋ฌธ์์ด๋ก ์ฐ๊ฒฐํ ์ ์๋ ๋ด์ฅ js๋ฐฐ์ด ๋ฉ์๋์ด๋ค.
'Study_Develop > ์๊ณ ๋ฆฌ์ฆ | ์ฝ๋ฉํ ์คํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค - ๋ง์ ์ ์ถ๋ ฅํ๊ธฐ - JS (0) | 2023.07.23 |
---|---|
ํ๋ก๊ทธ๋๋จธ์ค - ํน์ ๋ฌธ์ ์ถ๋ ฅํ๊ธฐ - JS (1) | 2023.07.23 |
ํ๋ก๊ทธ๋๋จธ์ค - ๋ฌธ์์ด ๋ฐ๋ณตํด์ ์ถ๋ ฅํ๊ธฐ - js (repeat()ํจ์ ์ฌ์ฉ๋ฒ) (0) | 2023.07.23 |
์ฝ๋ฉํ ์คํธ a์ b์ถ๋ ฅํ๊ธฐ - javascript (0) | 2023.07.23 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฌธ์์ด ์ถ๋ ฅํ๊ธฐ JavaScript (feat. readline์ฌ์ฉ๋ฒ) (1) | 2023.07.21 |