Without nesting loops, how are you able to form such an ascii art?
####
###
##
#
This is what I currently have:
function invertTriangle (row) {
var asteric = "*" * row;
for ( var y=row; y>=row; y--){
asteric = asteric - "*";
console.log(asteric);
}
};
invertTriangle(10);
I will appreciate your help and explanation!
Thank you!
Here's a way of doing it with recursion.
Basically, you call the function with the number of chars you'd like printed on the first line. It then constructs a string with this many characters in it. It then decrements the number of chars wanted and, if this number is greater than 0, calls itself again and adds the new result to the current result. This continues until we get to a line that requires zero characters. At this point, the function no longer calls itself and the fully constructed string is returned to the original caller.
Code: