// 작성코드
function readVertically(arr) {
let result = "";
let maxLength = 0;
for (let str of arr) {
if (str.length > maxLength) {
maxLength = str.length;
}
}
for (let i = 0; i < maxLength; i++) {
for (let str of arr) {
if (str[i]) {
result += str[i];
}
}
}
return result;
}
// 작성코드2
function readVertically(arr) {
let maxLength = Math.max(...arr.map(str => str.length));
return [...Array(maxLength).keys()].map(i =>
arr.reduce((res, str) => res + (str[i] || ''), '')
).join('');
}
// 레퍼런스 코드
function readVertically(arr) {
let temp = [];
for (let i = 0; i < arr.length; i++) {
let str = arr[i];
for (let j = 0; j < str.length; j++) {
if (temp.length === j) {
temp.push(str[j]);
} else {
temp[j] = temp[j] + str[j];
}
}
}
let result = '';
for (let i = 0; i < temp.length; i++) {
result = result + temp[i];
}
return result;
}