-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPattern-9 Diamond-Star-Pattern.js
64 lines (54 loc) · 1.34 KB
/
Pattern-9 Diamond-Star-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
function diamondStarPattern(num) {
starPyramid(num);
InvertedStarPyramid(num);
}
function starPyramid(num) {
// This is the outer loop which will loop for the rows.
for (let i = 0; i < num; i++) {
// For printing the spaces before stars in each row
for (let j = 0; j < num - i - 1; j++) {
process.stdout.write(" ");
}
// For printing the stars in each row
for (let j = 0; j < 2 * i + 1; j++) {
process.stdout.write("*");
}
// For printing the spaces after the stars in each row
for (let j = 0; j < num - i - 1; j++) {
process.stdout.write(" ");
}
console.log();
}
}
function InvertedStarPyramid(num) {
// This is the outer loop which will loop for the rows.
for (let i = 0; i < num; i++) {
// For printing the spaces before stars in each row
for (let j = 0; j < i; j++) {
process.stdout.write(" ");
}
// For printing the stars in each row
for (let j = 0; j < 2 * num - (2 * i + 1); j++) {
process.stdout.write("*");
}
// For printing the spaces after the stars in each row
for (let j = 0; j < i; j++) {
process.stdout.write(" ");
}
console.log();
}
}
diamondStarPattern(6);
// OUTPUT
// *
// ***
// *****
// *******
// *********
// ***********
// ***********
// *********
// *******
// *****
// ***
// *