File tree 2 files changed +57
-0
lines changed
2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ <h1 >Build Tower <sup ><sup >6 Kyu</sup ></sup ></h1 >
2
+
3
+ <sup >
4
+ <a href =" https://www.codewars.com/kata/576757b1df89ecf5bd00073b " >
5
+ <strong>LINK TO THE KATA</strong>
6
+ </a > - <code >STRINGS</code > <code >ASCII ART</code > <code >FUNDAMENTALS</code >
7
+ </sup >
8
+
9
+ ## Description
10
+
11
+ 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.
12
+
13
+ For example, a tower with ` 3 ` floors looks like this:
14
+
15
+ ```
16
+ [
17
+ " * ",
18
+ " *** ",
19
+ "*****"
20
+ ]
21
+ ```
22
+
23
+ And a tower with ` 6 ` floors looks like this:
24
+
25
+ ```
26
+ [
27
+ " * ",
28
+ " *** ",
29
+ " ***** ",
30
+ " ******* ",
31
+ " ********* ",
32
+ "***********"
33
+ ]
34
+ ```
35
+
36
+ ## Solution
37
+
38
+ ``` javascript
39
+ const towerBuilder = nFloors => {
40
+ const piramidBase = nFloors * 2 - 1
41
+ let floorsArray = []
42
+
43
+ for (let i = 1 ; i < nFloors + 1 ; i++ ) {
44
+ const currentFloorBase = i * 2 - 1
45
+ const bricks = ' *' .repeat (currentFloorBase)
46
+ const spaceDifference = (piramidBase - currentFloorBase) / 2
47
+ const blankSpace = ' ' .repeat (spaceDifference)
48
+
49
+ const floorBuilt = ` ${ blankSpace}${ bricks}${ blankSpace} `
50
+
51
+ floorsArray .push (floorBuilt)
52
+ }
53
+
54
+ return floorsArray
55
+ }
56
+ ```
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
25
25
- ** [ Array.diff] ( ./6-kyu/array-diff.md ) **
26
26
- ** [ Bit Counting] ( ./6-kyu/bit-counting.md ) **
27
27
- ** [ Break camelCase] ( ./6-kyu/break-camel-case.md ) **
28
+ - ** [ Build Tower!] ( ./6-kyu/build-tower.md ) **
28
29
- ** [ Card game] ( ./6-kyu/card-game.md ) **
29
30
- ** [ Checkered Board] ( ./6-kyu/checkered-board.md ) **
30
31
- ** [ Convert string to camel case] ( ./6-kyu/convert-string-to-camel-case.md ) **
You can’t perform that action at this time.
0 commit comments