Here is the code to display pyramid but its not exactly producing required output.
One line of code:
function generatePyramid(n) { return [...Array(n)] .forEach((_, i) => console.log([...Array(++i)].map((_, j) => ++j).join(' '))); }