Last active
February 25, 2022 15:52
-
-
Save vvgomes/ac27c8b2d5a0937c3228701d3f336f11 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
height = 6 | |
.....∆ | |
....∆∆∆ | |
...∆∆∆∆∆ | |
..∆∆∆∆∆∆∆ | |
.∆∆∆∆∆∆∆∆∆ | |
∆∆∆∆∆∆∆∆∆∆∆ | |
*/ | |
function buildPyramid(height, layerCount = 1, pyramid = []) { | |
if (layerCount > height) return pyramid.join("\n"); | |
const padCount = height + layerCount - 1; | |
const brickCount = layerCount * 2 - 1; | |
const layer = | |
Array(brickCount) | |
.fill("∆", 0, brickCount) | |
.join("") | |
.padStart(padCount, " "); | |
return buildPyramid(height, layerCount + 1, pyramid.concat(layer)); | |
} | |
console.log(buildPyramid(12)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment