[프로그래머스]연습문제 - 문자열 내 p와 y의 개수

·2021년 10월 31일
0

코테문제풀기

목록 보기
33/57

문제확인

https://programmers.co.kr/learn/courses/30/lessons/12916

문제풀이

function solution(s){
  const lowerS = s.toLowerCase();
  let countP = 0, countY = 0;
  
  for(let i = 0; i < s.length; i++) {
    if(lowerS[i] === 'p') countP++;
    else if(lowerS[i] === 'y') countY++;
  }

  if (countP === countY) return true;
  else return false;
}

0개의 댓글