-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPattern-20 Symmetric-Butterfly-Pattern.js
More file actions
47 lines (40 loc) · 1.01 KB
/
Pattern-20 Symmetric-Butterfly-Pattern.js
File metadata and controls
47 lines (40 loc) · 1.01 KB
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
function symmetricButterflyPattern(num) {
// initialising the spaces.
let spaces = 2 * num - 2;
// Outer loop for printing row.
for (let i = 1; i <= 2 * num - 1; i++) {
// stars for first half
let stars = i;
// stars for the second half.
if (i > num) stars = 2 * num - i;
//for printing the stars
for (let j = 1; j <= stars; j++) {
process.stdout.write("*");
}
//for printing the spaces
for (let j = 1; j <= spaces; j++) {
process.stdout.write(" ");
}
//for printing the stars
for (let j = 1; j <= stars; j++) {
process.stdout.write("*");
}
// As soon as the stars for each iteration are printed, we move to the
// next row and give a line break otherwise all stars
// would get printed in 1 line.
console.log();
if (i < num) spaces -= 2;
else spaces += 2;
}
}
symmetricButterflyPattern(5);
// OUTPUT
// * *
// ** **
// *** ***
// **** ****
// **********
// **** ****
// *** ***
// ** **
// * *