Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Last active September 16, 2022 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonbosa/102c063663e2528b96823c81692d2d32 to your computer and use it in GitHub Desktop.
Save andersonbosa/102c063663e2528b96823c81692d2d32 to your computer and use it in GitHub Desktop.
function parse_frame_by_size (size, i) {
const spaces_to_add = size - i
const bricks_to_add = i
let frame = ""
for (let n = 1; n <= spaces_to_add; n++) {
frame = frame + " "
}
for (let n = 1; n <= bricks_to_add; n++) {
frame = frame + "#"
}
return frame + `\n`
}
function mount_staircase(size = 8) {
let screen = ""
for (let i = 1; i <= size; i++ ) {
const frame = parse_frame_by_size(size, i)
screen = screen + frame
}
return screen
}
console.log( mount_staircase() )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment