[英]How to make upside-down inverted triangle pattern
需要时需要在开头填写空格:
let stars = ''; for (let i = 0; i < 10; i++) { for (let j = 0; j < 10; j++) { stars += (j >= i)? '*': ' '; } stars += (i === 9)? '': '\n'; } console.log(stars);
var stars = ''; // number of spaces var k = 2*10 - 2; // Outer loop to handle number of rows // n in this case for (var i = 10; i > 0; i--) { // Inner loop to handle number spaces // values changing acc. to requirement for (var j = 0; j < 10-i; j++) { stars += ' '; } k = k-2 // Inner loop to handle number of columns // values changing acc. to outer loop for(var j = 0; j < i; j++){ stars += '*'; } stars += "\n"; } console.log(stars);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.