curriculum/challenges/english/blocks/lab-pyramid-generator/66f2836c459cfb16ae76f24f.md
Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.
User Stories:
pyramid that takes three arguments.pyramid function should return a string in which the pattern character is repeated and arranged to form a pyramid having the vertex facing upwards when the third argument is false.true the pyramid should have the vertex facing downwards.For example, calling pyramid("o", 4, false) should give this output:
o
ooo
ooooo
ooooooo
You should have a function named pyramid.
assert.isFunction(pyramid);
Your pyramid function should have three parameters.
assert.lengthOf(pyramid, 3);
pyramid("o", 4, false) should return "\n o\n ooo\n ooooo\nooooooo\n".
assert.equal(pyramid("o", 4, false), "\n o\n ooo\n ooooo\nooooooo\n")
pyramid("p", 5, true) should return "\nppppppppp\n ppppppp\n ppppp\n ppp\n p\n".
assert.equal(pyramid("p", 5, true), "\nppppppppp\n ppppppp\n ppppp\n ppp\n p\n")
function pyramid(char, count, isInverted) {
const rows = []
for (let i = 1; i <= count; i++) {
if (isInverted) {
rows.unshift(" ".repeat(count - i) + char.repeat(2 * i - 1))
} else {
rows.push(" ".repeat(count - i) + char.repeat(2 * i - 1))
}
}
return "\n" + rows.join("\n") + "\n";
}
console.log(pyramid("#", 10, false))