You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
365 B
TypeScript

export const towerBuilder = (nFloors: number): string[] => {
const floors: string[] = [];
for (let n = 1; n < nFloors + 1; n++) {
const stars = "*".repeat(n * 2 - 1);
const space = ' '.repeat(nFloors - n);
const res = space + stars + space;
floors.push(res);
}
return floors;
}
console.log(towerBuilder(3))
console.log(towerBuilder(6))