문자열을 요소로 갖는 배열을 입력받아 문자열을 세로로 읽었을 때의 문자열을 리턴해야 합니다.
string
타입을 요소로 갖는 배열
string
타입을 리턴해야 합니다.
let input = [ // 'hello', 'wolrd', ]; let output = readVertically(input); console.log(output); // --> 'hweolllrod' input = [ // 'hi', 'wolrd', ]; output = readVertically(input); console.log(output); // --> 'hwiolrd'
function readVertically(arr) {
let maxLength = 0;
for(let i = 0; i < arr.length; i++){
if(maxLength < arr[i].length){
maxLength = arr[i].length;
}
}
let result = '';
for(let i = 0; i < maxLength; i++){
for(let j = 0; j < arr.length; j++){
if(arr[j][i] === undefined){ // 이 부분이 백미임
continue;
}
result += arr[j][i];
}
}
return result;
}