How to display pyramid using JavaScript?

前端 未结 22 867
长情又很酷
长情又很酷 2020-11-29 11:45

Here is the code to display pyramid but its not exactly producing required output.

22条回答
  •  情话喂你
    2020-11-29 12:27

    Another Option

    One line of code:

    function generatePyramid(n) {
        return [...Array(n)]
            .forEach((_, i) => console.log([...Array(++i)].map((_, j) => ++j).join(' ')));
    }
    

提交回复
热议问题