728x90
function solution(s) {
const count = { p: 0, y: 0 };
for (const char of s.toLowerCase()) {
char === 'p' && count.p++;
char === 'y' && count.y++;
}
return count.p === count.y || (count.p === 0 && count.y === 0) ? true : false;
}
count ๋ผ๋ obj ๋ฅผ ๋ง๋ค์ด์ p ์ y ๋ฅผ ์ฐพ๋๋ค. ์ฐพ๋ ๋ฌธ์๋ ์๋ฌธ์๋ก ํต์ผ์์ผฐ๋ค.
count ์ p ์ y ๊ฐ ๊ฐ๋ค๋ฉด ture, ๋๋ค 0 ์ด๋ฉด false ๋ฅผ ์ถ๋ ฅํ๋ค.
728x90
๋ฐ์ํ