[6kyu][string] towerBuilder

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:
main
Vasily Guzov 1 year ago
parent 3a1b17fb9f
commit f0bff99aa4

@ -0,0 +1,17 @@
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))
Loading…
Cancel
Save