DEV Community

Discussion on: Daily Challenge #52 - Building a Pyramid

Collapse
 
gnsp profile image
Ganesh Prasad
const pyramid = n => Array(n).fill(1)
    .map((_, lineno) => lineno * 2 + 1)
    .map(x => [x, (n * 2 - 1 - x) / 2])
    .map(([x, y]) => [Array(x).fill('*').join(''), Array(y).fill(' ').join('')])
    .map(([x, y]) => `${y}${x}${y}`).join('\n');