题目描述
题解
function output(str) {const strLength = str.length;let totalLine = 0;let containerSize = 0;while (containerSize < strLength) {containerSize += totalLine * 2 + 1;totalLine++;}let result = '';let startIndex = 0;for (let curLine = 1; curLine <= totalLine; curLine++) {const endIndex = startIndex + 2 * curLine - 1;output += ' '.repeat(totalLine - curLine) + str.slice(startIndex, endIndex) + '\n';startIndex = endIndex;}console.log(result);}
