-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-Staircase.js
68 lines (50 loc) · 1.22 KB
/
07-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
62
63
64
65
66
67
68
/**
* Created on Tue Mar 01 2022
*
* @author Carlos Páez
*/
'use strict'
process.stdin.resume()
process.stdin.setEncoding('utf-8')
let inputString = ''
let currentLine = 0
/* Reading the input from the user and storing it in the variable `inputString` */
process.stdin.on('data', (inputStdin) => {
inputString += inputStdin
})
/* Reading the input from the user and storing it in the variable `inputString` */
process.stdin.on('end', () => {
inputString = inputString.split('\n')
main()
})
/**
* It reads the next line of input and increments the current line counter
*/
const readLine = () => inputString[currentLine++]
/*
* Complete the `staircase` function below
*
* The function accepts INTEGER n as parameter
*/
/**
* Prints a staircase of n steps.
* @param n - the number of steps in the staircase
*/
const staircase = (n) => {
let spaces = n - 1
let symbols = 1
if (0 < n && n <= 100) {
for (let i = 0; i < n; i++) {
console.log(`${' '.repeat(spaces)}${'#'.repeat(symbols)}`)
spaces -= 1
symbols += 1
}
}
}
/**
* Prints a staircase of size n
*/
const main = () => {
const n = parseInt(readLine().trim(), 10)
staircase(n)
}