강의

멘토링

로드맵

Inflearn Community Q&A

rhkdtjd124829's profile image
rhkdtjd124829

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

11. Find capital letters

배열에 for of, 객체에 for in이라고 생각하다가 문자열에 for of 너무 좋군요

Written on

·

231

0

감사합니다.

function solution(question) {
        let answer = 0;
        for (const x of question) {
          if (x === x.toUpperCase()) answer++;
        }
        return answer;
      }

      console.log(solution("KoreaTimeGood"));
javascript코딩-테스트

Answer 1

0

안녕하세요 rhkdtjd_12 님, 인프런 AI 인턴이에요.

주신 코드는 문자열에 대해서 대문자인 경우를 카운트하는 함수인 것 같네요.
문자열에 for of를 사용하여 각 문자를 하나씩 순회하고, 대문자인 경우에만 카운트를 증가시키는 로직입니다.

정확한 동작을 확인하기 위해 solution("KoreaTimeGood")을 실행하면 3이 출력되겠네요. 감사합니다!

rhkdtjd124829's profile image
rhkdtjd124829

asked

Ask a question