-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPattern-19 Symmetric-Void-Pattern.js
72 lines (60 loc) · 1.66 KB
/
Pattern-19 Symmetric-Void-Pattern.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
69
70
71
72
function SymmetricVoidPattern(num) {
// for the upper half of the pattern.
// initial spaces.
let iniS = 0;
for (let i = 0; i < num; i++) {
//for printing the stars in the row.
for (let j = 1; j <= num - i; j++) {
process.stdout.write("*");
}
//for printing the spaces in the row.
for (let j = 0; j < iniS; j++) {
process.stdout.write(" ");
}
//for printing the stars in the row.
for (let j = 1; j <= num - i; j++) {
process.stdout.write("*");
}
// The spaces increase by 2 every time we hit a new row.
iniS += 2;
// As soon as the letters for each iteration are printed, we move to the
// next row and give a line break otherwise all letters
// would get printed in 1 line.
console.log();
}
// for lower half of the pattern
// initial spaces.
iniS = 2 * num - 2;
for (let i = 1; i <= num; i++) {
//for printing the stars in the row.
for (let j = 1; j <= i; j++) {
process.stdout.write("*");
}
//for printing the spaces in the row.
for (let j = 0; j < iniS; j++) {
process.stdout.write(" ");
}
//for printing the stars in the row.
for (let j = 1; j <= i; j++) {
process.stdout.write("*");
}
// The spaces decrease by 2 every time we hit a new row.
iniS -= 2;
// As soon as the letters for each iteration are printed, we move to the
// next row and give a line break otherwise all letters
// would get printed in 1 line.
console.log();
}
}
SymmetricVoidPattern(5);
// OUTPUT
// **********
// **** ****
// *** ***
// ** **
// * *
// * *
// ** **
// *** ***
// **** ****
// **********