The Hourglass Pattern

MediumAcc. 87.6%
+30 XP 12

Temporal Symmetry

An hourglass consists of a full downward triangle followed by a full upward triangle, sharing a single-star center.

The Assignment

Your function receives width (must be odd).

  1. First block: Draw downward triangle (from width stars down to 1).
  2. Second block: Draw upward triangle (from 3 stars up to width).
  3. Correct leading spaces for every row to center the stars.

01EXAMPLE 1

Inputwidth = 3
Output*** * ***

Explanation: The 3x3 hourglass.

Constraints

  • Must handle leading spaces correctly.
  • Assume width is odd.
MathLoops
JavaScript
Loading...
1 Hidden

Input Arguments

width3

Expected Output

***
 * 
***

Click RUN to test your solution