Tell us what’s happening:
I can’t figure out steps 3 and 4, Not understanding how to achieve the desired result, any assistance wii be appreciated.
Your code so far
function pyramid(str, count, bool){
const rows = [];
let results = "";
if (bool === false){
for (let i = 1; i <= count; i++){
rows.push(" ".repeat(count - i) + str.repeat((i*2 -1) ) + " ".repeat(count - i))
}} else {
for (let i = 1; i <= count; i++){
rows.unshift(" ".repeat(count - i) + str.repeat((2 * i) -1 ) + " ".repeat(count - i));
} }
for (const row of rows){
results += row+ '\n';
}
return results;
}
let test = pyramid("o", 4, false);
console.log(test);
test = pyramid("p",5,true)
console.log(test)
console.log(JSON .stringify(pyramid("o",4,false)))
console.log('\n')
console.log(JSON.stringify(pyramid("p",5,true)))
//console.log('\n``')
//console.log(JSON.stringify("\n o\n ooo\n ooooo\nooooooo\n"));
//console.log('\n``')
//console.log(JSON.stringify("\nppppppppp\n ppppppp\n ppppp\n ppp\n p\n"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator