I was messing around with some basic algorithms. I wanted to know if someone has a shorter version of this one in JS to display the pyramid:
const total= 30;
let line = 1;
for (let i = 1; i < total; i = i + 2) {
console.log(' '.repeat(total / 2 - line) + '*'.repeat(i))
line++;
}
lineori, as both increase by a set amount each iteration. (Note thati = line * 2 - 1.) After that, there are some micro-optimizations, but usually the browser takes care of those.