Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 83272a7

Browse files
feat: add pattern programming 2
1 parent 9da02b4 commit 83272a7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎Topic4/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,41 @@ for (let i = 1; i <= 5; i++) {
7777
}
7878
console.log();
7979
}
80+
81+
// mirror right angle triangle
82+
for (let i = 1; i <= 5; i++) {
83+
// inverted
84+
for (let j = 1; j <= 5 - i; j++) {
85+
process.stdout.write(" ");
86+
}
87+
88+
// right
89+
for (let j = 1; j <= i; j++) {
90+
process.stdout.write("* ");
91+
}
92+
console.log();
93+
}
94+
95+
// X pattern
96+
for (let i = 1; i <= 5; i++) {
97+
for (let j = 1; j <= 5; j++) {
98+
if (j === i || j + i === 5 + 1) {
99+
process.stdout.write("* ");
100+
} else {
101+
process.stdout.write(" ");
102+
}
103+
}
104+
console.log();
105+
}
106+
107+
// V pattern
108+
for (let i = 1; i <= 5; i++) {
109+
for (let j = 1; j <= 2 * 5 - 1; j++) {
110+
if (j === i || j + i === 9 + 1) {
111+
process.stdout.write("* ");
112+
} else {
113+
process.stdout.write(" ");
114+
}
115+
}
116+
console.log();
117+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /