Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: convert pyramid generator project into lab #590

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions frontend-cert/js-projects/lab-pyramid-generator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function pyramid(char, count, isInverted) {
const rows = []
for (let i = 1; i <= count; i++) {
if (isInverted) {
rows.unshift(" ".repeat(count - i) + char.repeat(2 * i - 1))
} else {
rows.push(" ".repeat(count - i) + char.repeat(2 * i - 1))
}
}
return "\n" + rows.join("\n");
}

console.log(pyramid("#", 10, false))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1. You should have a function name `pyramid` that takes three arguments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. You should have a function name `pyramid` that takes three arguments.
1. You should have a function named `pyramid` that takes three arguments.

1. The first argument should be a string representing the pattern character to repeat in your pyramid.
1. The second argument should be an integer representing the number of rows in the pyramid.
1. The third argument should be a Boolean value.
1. `pyramid` should return a string in which the pattern character is repeated and arranged to form a pyramid having the vertex facing upwards when the third argument is `false`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. `pyramid` should return a string in which the pattern character is repeated and arranged to form a pyramid having the vertex facing upwards when the third argument is `false`.
1. The `pyramid` function should return a string in which the pattern character is repeated and arranged to form a pyramid having the vertex facing upwards when the third argument is `false`.

1. When the third argument is `true` the pyramid should have the vertex facing downwards.
1. The vertex row should have a single pattern character, and each other row should have two pattern characters more than the previous one.