Skip to content

Instantly share code, notes, and snippets.

@sh4hids
Created August 5, 2019 08:27
Show Gist options
  • Save sh4hids/95cb55460d02d6aea71142e585bb2d2d to your computer and use it in GitHub Desktop.
Save sh4hids/95cb55460d02d6aea71142e585bb2d2d to your computer and use it in GitHub Desktop.
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