Created
March 27, 2021 14:44
-
-
Save zapkub/3d030b37f7dea90606f244e5618e0642 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 renderDiamond(input) { | |
let preSpace = (input - 1) / 2 | |
let postSpace = (input - 1) / 2 | |
let output = "" | |
let f = (input - 1) / 2 | |
for (var line = 0; line < input; line++) { | |
for (var col = 0; col < input; col++) { | |
if (col < preSpace || col > postSpace) { | |
output = output + "_" | |
} else { | |
output = output + "*" | |
} | |
} | |
output = output + "\n" | |
if (line < f) { | |
preSpace = preSpace - 1 | |
postSpace = postSpace + 1 | |
} else { | |
preSpace = preSpace + 1 | |
postSpace = postSpace - 1 | |
} | |
} | |
console.log(output) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment