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.

  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 - 1 down to 1).
  2. For each row, print the leading spaces to center the * symbols.

01EXAMPLE 1

Inputheight = 2
Output * *** *

Explanation: A small diamond.

Constraints

  • Total width matches the longest row.
  • Symmetry is mandatory.
MathLoopsGeometry
JavaScript
Loading...
2 Hidden

Input Arguments

height2

Expected Output

 *
***
 *

Click RUN to test your solution