문제 : https://programmers.co.kr/learn/courses/30/lessons/12916
체감난이도 ☆☆ (쉽게 넘 풀었지만 다른 더 좋은 방법이 많은 것 같다)
function solution(idx) {
const CntP = [...idx].filter((el) => el === 'p' || el === 'P').length;
const CntY = [...idx].filter((el) => el === 'y' || el === 'Y').length;
return CntP === CntY;
}
방식1
function solution(idx) {
return (
idx.toUpperCase().split('P').length === idx.toUpperCase().split('Y').length
);
}
방식2
function solution(idx) {
// console.log(idx.match(/p/gi)); // ["p","P"]
return (idx.match(/p/gi) || []).length === (idx.match(/y/gi) || []).length;
}