Created
August 5, 2019 08:27
-
-
Save sh4hids/95cb55460d02d6aea71142e585bb2d2d to your computer and use it in GitHub Desktop.
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 generateBaklava(length = 1){ | |
let l = (length * 2) + 1; | |
for(let i = 0; i < l; i++){ | |
let str = ''; | |
for(let j = 0; j < l; j++){ | |
if (i <= l/2) { | |
if(j >= parseInt(l/2, 10) - i && j <= parseInt(l/2, 10) + i ) { | |
str += "*"; | |
} else { | |
str += " "; | |
} | |
} else { | |
if(j >= i-parseInt(l/2,10) && j <= (l - ((i+1) -parseInt(l/2,10)))) { | |
str += "*"; | |
} else { | |
str += " "; | |
} | |
} | |
} | |
console.log(str); | |
} | |
} | |
generateBaklava(4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment