Created
September 21, 2018 19:20
-
-
Save spektraldevelopment/e42e4f8c3ac9c865c4d86011007d8349 to your computer and use it in GitHub Desktop.
JS: Pyramid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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