-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstaircase.js
63 lines (52 loc) · 805 Bytes
/
staircase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
*
* -----------
* | STAIRCASE |
* -----------
*
* Write a program that prints a staircase of size n
* where n is the height and width of bass
*
* e.g.
*
* staircase(4)
*
* prints this...
*
* #
* ##
* ###
* ####
*
*
* */
/*
*
* ***** SOLUTION
*
* */
function staircase(n) {
for(let i = 1; i <= n; i++){
const output = "#".repeat(i);
const spaces = " ".repeat(n - i);
console.log(spaces + output);
};
return null;
};
/*
* ***** TESTS
*
* */
console.log("## TEST 1 ----- > ", staircase(4));
/*
*
* #
* ##
* ###
* ####
*
* */
// const numsArr2 = null;
// console.log("## TEST 2 ----- > ", staircase(numsArr2)); // 100
// const numsArr3 = null;
// console.log("## TEST 3 ----- > ", staircase(numsArr3)); // 128