[프로그래머스] JadenCase-string 문자열 만들기

·2022년 12월 19일
0

코테문제풀기

목록 보기
55/57
function solution(s) {
  const answer = s.split(" ").reduce((answer, word) => {
    if (word === "") return answer + " ";

    const first = word[0];
    const rest = word.substring(1, word.length).toLowerCase();
    let newWord = "";

    if (`${parseInt(first)}` !== "NaN") {
      newWord = first + rest;
    } else {
      newWord = first.toUpperCase() + rest;
    }

    return answer ? answer + " " + newWord : newWord;
  }, "");

  return answer;
}

참고

typeof NaN === 'number'
not a number 라서 number 타입임
참고자료 : typeof NaN === 'number'

0개의 댓글