문제
JadenCase 문자열 만들기
문제풀이
function solution(s) {
var answer = '';
var arr = [];
arr = s.split(' ');
for (var i = 0; i < arr.length; i++) {
var sentence = [...arr[i]];
if (sentence[0] >= 'a' && sentence[0] <= 'z') {
var word = sentence[0];
var UPPERCASE_WORD = String.fromCharCode(word.charCodeAt(0) - 32);
sentence[0] = UPPERCASE_WORD;
}
for (var j = 1; j < sentence.length; j++) {
if (sentence[j] >= 'A' && sentence[j] <= 'Z') {
var word = sentence[j];
var LOWERCASE_WORD = String.fromCharCode(word.charCodeAt(0) + 32);
sentence[j] = LOWERCASE_WORD;
}
}
answer += ' ' + sentence.join('');
}
answer = answer.substring(1);
return answer;
}