
function solution(str, t){
let result = 0;
for(let x of str) {
if(x==t) result++;
console.log(x);
}
return result;
}
let str = 'COMPUTERPROGRAMMING' ;
console.log(solution(str,'R'));
function solution(str, t){
let result = str.split(t).length;
return result-1;
}
let str = 'COMPUTERPROGRAMMING' ;
console.log(solution(str,'R'));
⇒ split() 메서드는 전달받은 인수를 기준으로 문자열을 자르는 것
⇒ 문자열을 자른 덩어리는 R의 갯수 + 1