-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathpattern8.js
40 lines (36 loc) · 954 Bytes
/
pattern8.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
/**
* @author MadhavBahl
* @date 26/12/2018
*/
function pattern8 (n) {
let currentLine;
// Print upper pattern
for (let i=1; i<=n; i++) {
currentLine = '';
for (let j=1; j<=2*n; j++) {
if (j<=n) {
if (i<j) currentLine += ' ';
else currentLine += '* ';
} else {
if (i+j < 2*n + 1) currentLine += ' ';
else currentLine += '* ';
}
}
console.log(currentLine);
}
// Print lower pattern
for (let i=1; i<=n; i++) {
currentLine = '';
for (let j=1; j<=2*n; j++) {
if (j<=n) {
if (i+j>n+1) currentLine += ' ';
else currentLine += '* ';
} else {
if (i > j-n) currentLine += ' ';
else currentLine += '* ';
}
}
console.log(currentLine);
}
}
pattern8 (5);