Skip to content

Instantly share code, notes, and snippets.

@spektraldevelopment
Created September 21, 2018 19:20
Show Gist options
  • Save spektraldevelopment/e42e4f8c3ac9c865c4d86011007d8349 to your computer and use it in GitHub Desktop.
Save spektraldevelopment/e42e4f8c3ac9c865c4d86011007d8349 to your computer and use it in GitHub Desktop.
JS: Pyramid
function pyramid(n) {
const midpoint = Math.floor((2 * n - 1) / 2);
for (let row = 0; row < n; row++) {
let level = '';
for (let column = 0; column < 2 * n - 1; column++) {
if (midpoint - row <= column && midpoint + row >= column) {
level += "#";
} else {
level += " ";
}
}
console.log(level);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment