To print a hollow inverted pyramid pattern in TypeScript, we use nested loops to manage spaces and stars.
In this example,
function printHollowInvertedPyramid(numRows: number): void {
for (let row: number = numRows; row >= 1; row--) {
let pattern: string = '';
for (let space: number = 0; space < numRows - row; space++) {
pattern += ' ';
}
if (row === numRows || row === 1) {
pattern += '*'.repeat(2 * row - 1);
} else {
pattern += '*';
pattern += ' '.repeat(2 * row - 3);
pattern += '*';
}
console.log(pattern);
}
}
printHollowInvertedPyramid(5);
********* * * * * * * *
In this tutorial, we learned How to print Hollow Inverted Pyramid Pattern in TypeScript language with well detailed examples.