The Diamond Loom
HardAcc. 78.1%
+40 XP 20
Centered Symmetry
A diamond pattern consists of a centered upward triangle followed by a centered downward triangle.
The Assignment
Your function receives a parameter height (representing the midpoint row). Total rows will be 2 * height - 1.
- Use two separate nested loop blocks:
- Part 1: Top half including the peak (loop from 1 to
height). - Part 2: Bottom half excluding the peak (loop from
height - 1down to 1).
- Part 1: Top half including the peak (loop from 1 to
- For each row, print the leading spaces to center the
*symbols.
01EXAMPLE 1
Input
height = 2Output
*
***
*Explanation: A small diamond.
Constraints
- Total width matches the longest row.
- Symmetry is mandatory.
MathLoopsGeometry
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
height2
Expected Output
* *** *
Click RUN to test your solution