ํ์ ๊ณต๋ถ/๐ซง ์๊ณ ๋ฆฌ์ฆ ๊ณต๋ถ
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฌธ์์ด ๋ด p์ y์ ๊ฐ์
๋์๐
2024. 9. 5. 11:56
728x90
์ฝํ ๋ฌธ์ ํ๊ธฐ ๋ค์ ์์!
function solution(s){
const chars = s.split('').map(v=> v.toLowerCase());
let countP = 0;
let countY = 0;
chars.map(v=> {
v==='p' && countP++;
v==='y' && countY++;
} )
if(countP === 0 && countY === 0){
return true
} else{
return countP===countY ? true :false
}
}
๋์๋ฌธ์๋ฅผ ํต์ผํด์ค ํ p ์ y ์ ๊ฐ์๋ฅผ ์ธ์คฌ๋๋ฐ,
function numPY(s){
return s.toUpperCase().split("P").length === s.toUpperCase().split("Y").length;
}
์ ์ด์ p ๋ y ๋ฅผ split ์ผ๋ก ์ ๊ฑฐ ํ ๋จ์ ๋ฌธ์์ ๊ฐ์๋ฅผ ์ธ์ด์ฃผ๋ ๊น์ํ ๋ฐฉ๋ฒ์ ๋ฐ๊ฒฌํ๋ค.
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/032.gif)
728x90
๋ฐ์ํ