Last active
December 6, 2016 17:48
-
-
Save armenr/b7992b1b2468005f643bdf426e821da9 to your computer and use it in GitHub Desktop.
buildTriangle.js
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
function buildTriangle(numLines) { | |
var linesArray = []; | |
var iterations = numLines; | |
if (numLines < 1 ) { | |
return alert("Try a bigger number!") | |
} | |
for (var line = 1; line <= iterations; line++) { //start @ 1 instead of zero to avoid empty first index string | |
linesArray.push("#".repeat(line) + "\n"); | |
} | |
return console.log(linesArray.join("")); | |
} |
Edited. Thanks for the suggestion!
Try this - I think it makes it more readable: https://jsfiddle.net/q9xywy8m/5/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LGTM. I would consider maybe handling
numLines
with any value less then1
.Maybe something like..