Skip to content

Instantly share code, notes, and snippets.

@armenr
Last active December 6, 2016 17:48
Show Gist options
  • Save armenr/b7992b1b2468005f643bdf426e821da9 to your computer and use it in GitHub Desktop.
Save armenr/b7992b1b2468005f643bdf426e821da9 to your computer and use it in GitHub Desktop.
buildTriangle.js
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(""));
}
@davehallman
Copy link

davehallman commented Dec 6, 2016

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