LoopsX Studio
No. 25 / Advanced

Hollow Butterfly

Outputn = 5
*        *
**      **
* *    * *
*  *  *  *
*   **   *
*  *  *  *
* *    * *
**      **
*        *
9 rows
Controls
5
Character
Normal
How it works

Same grid as the butterfly, but only the outline of the wings is kept: the first and last column, plus the two diagonal edges of each wing.

rows 2n − 1columns 2nstar when (i <= n && (j == 1 || j == i || j == 2n − i + 1 || j == 2n)) || (i > n && (j == 1 || j == 2n − i || j == i + 1 || j == 2n))
pattern.js
1const n = 5;
2
3for (let i = 1; i <= 2 * n - 1; i++) {
4 let row = "";
5 for (let j = 1; j <= 2 * n; j++) {
6 if ((i <= n && (j === 1 || j === i || j === 2 * n - i + 1 || j === 2 * n)) || (i > n && (j === 1 || j === 2 * n - i || j === i + 1 || j === 2 * n))) {
7 row += "*";
8 } else {
9 row += " ";
10 }
11 }
12 console.log(row);
13}