Skip to content

Commit 56010d0

Browse files
authored
Create 10_Diamond.js
1 parent 541cd5f commit 56010d0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

22-Star-Pattern/10_Diamond.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Q25: Print diamond pattern
2+
// *
3+
// ***
4+
// *****
5+
// *******
6+
// *********
7+
// *******
8+
// *****
9+
// ***
10+
// *
11+
12+
let n = 5;
13+
14+
// upper half
15+
for (let i = 1; i <= n; i++) {
16+
let spaces = " ".repeat(n - i);
17+
let stars = "*".repeat(2 * i - 1);
18+
console.log(spaces + stars);
19+
}
20+
21+
// lower half
22+
for (let i = n - 1; i >= 1; i--) {
23+
let spaces = " ".repeat(n - i);
24+
let stars = "*".repeat(2 * i - 1);
25+
console.log(spaces + stars);
26+
}

0 commit comments

Comments
 (0)