Challenge
Write a function that will draw a pyramid. The function should take one integer parameter that will describe how many lines tall the pyramid should be.
This challenge is simple, but requires a bit of reflection to get it right. Here is an example in Node.js hosted on Repl.it.
Good luck!
This challenge comes from @aminnairi here on DEV! Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (20)
Fun challenge :) I did it in React, so here's the function:
and here's a demo!
Python one-liner yet again :)
Impeccable
I have no Go pun this time. Sorry, I need coffee for that.
pyramid.go
pyramid_test.go
Since this is pretty much the top half of a string diamond I took my answer from that challenge and used just the first half of the code but it isn't working like expected, can someone tell me where I went wrong? 😥
Ruby:
Here it is!
The right padding isn't necessary, but hey why not
My try. I used
padStart
andpadEnd
, and abused default parameters a bit, just for fun.CSS
This is a variation of my solution for challenge #2. Just add the class "triangle" to a block element, and specify the lines in the CSS variable
--stars
:The idea is having an inline SVG background with the asterisks, then clipping the shape of the triangle. Here is a demo on Codepen:
F#:
My solution in js