Language/JavaScript
[JavaScript] 프로그래머스 - JadenCase 문자열 만들기
어징베
2023. 3. 8. 20:59
문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/12951
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제풀이
const solution = (s) => {
const answer = s
.toLowerCase()
.split(" ")
.map(i => i.charAt(0).toUpperCase() + i.substring(1))
.join(" ");
return answer;
}
느낀점
- .map(i=> i[0].toUpperCase() + i.substring(1));를 썼을 때, 대문자로 바뀌지 않았다. 그 이유는 연속된 공백이 있을 경우 undefined가 반환되는 일이 생기기 때문이다.