f0bff99aa4
https://www.codewars.com/kata/576757b1df89ecf5bd00073b Build a pyramid-shaped tower, as an array/list of strings, given a positive integer number of floors. A tower block is represented with "*" character.For example, a tower with 3 floors looks like this:
18 lines
365 B
TypeScript
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))
|