loading...

re: Daily Challenge #52 - Building a Pyramid VIEW POST

FULL DISCUSSION
 

My try. I used padStart and padEnd, and abused default parameters a bit, just for fun.

const PYRAMID = "*";
const AIR = "ยท";

const pyramid = (n, {maxWidth = (n * 2) - 1, leftPadding = maxWidth / 2} = {}) => 
    Array.from({length: n}, (_, idx, __, {width = (( idx + 1 ) * 2) - 1} = {}) => 
        PYRAMID.repeat(width)
            .padStart(idx + leftPadding + 1, AIR)
            .padEnd(maxWidth, AIR)
    ).join("\n");
Code of Conduct Report abuse