To print a hollow pyramid pattern in TypeScript, you can follow similar logic as JavaScript using nested loops.
In this example,
function printHollowPyramid(rows: number): void {
for (let i = 1; i <= rows; i++) {
let pattern = '';
for (let j = i; j < rows; j++) {
pattern += ' ';
}
for (let k = 1; k < (2 * i); k++) {
if (k === 1 || k === (2 * i - 1) || i === rows) {
pattern += '* ';
} else {
pattern += ' ';
}
}
console.log(pattern);
}
}
printHollowPyramid(5);
* * * * * * * * * * * * * * * *
In this tutorial, we learned How to print Hollow Pyramid Pattern in TypeScript language with well detailed examples.