나의 해결방법

  <script>
        // function solution(s, t) {
        //     let sum = 0;
        //     for (let i = 0; i < str.length; i++) {
        //         if (s[i].includes(t)) {
        //             sum++
        //         }
        //     }

        //     return sum;
        // }

        // let str = "COMPUTERPROGRAMMING";
        // // console.log(str.length);
        // console.log(solution(str, 'R'));
</script>

내 풀이인데 

내 실수는 처음에 for문을 안적고 if만 해서 문자열길이(19)만큼 19가 답으로 출력됬다는것 

따라서 for문안에 if를 넣어야 원하는값을 잘 찾을수있다.

 

 

해결방법2) 

split('문자열') 로 특정 문자열 기준으로 나누기

 

해결방법3)

for x of s 로 for of 구문으로 해결하기

 

+ Recent posts