알고리즘_JS/프로그래머스_Level1
[프로그래머스 JavaScript] 이상한 문자 만들기
[리우]
2021. 7. 15. 15:36
프로그래머스 Level1 이상한 문자 만들기
문제 설명 : 생략
function solution(s) {
var answer = s.split(" ");
let result = [];
for(let an of answer){
for(let i=0; i<an.length; i++){
//짝수일경우 대문자
if(i%2 === 0){
result.push(an[i].toUpperCase());
//홀수일경우 소문자
}else{
result.push(an[i].toLowerCase());
}
}
//한 단어 끝나면 띄어쓰기
result.push(" ");
}
//마지막 띄어쓰기 없애기
result.pop();
//배열 문자열로 합치기
return result.join("");
}
728x90